Uploadify Rails 3.0 - Nothing happens after file is chosen

纵然是瞬间 提交于 2019-12-13 05:25:17

问题


I am trying to get uploadify to work with rails 3 but with little success. I have pretty much read everything there is to read about this, and tried pretty much everything, but nothing seems to work.

Heres my javascript/jquery.....with the form field.

<script type="text/javascript">
        $(document).ready(function() {
            $('#video_upload').click(function(event){
                event.preventDefault();
          });

        $('#video_upload').uploadify({
                'uploader'          : '/javascripts/uploadify/uploadify.swf',
                'script'            : '/videos/create',
                'sizeLimit'       : '2000.bytes',
                'cancelImg'         : '/images/cancel.png',
                'multi'             : false,
                'scriptData': { 'format': 'json', 'authenticity_token': encodeURIComponent('<%= form_authenticity_token if protect_against_forgery? %>') }
            });


          $('#video_submit').click(function(event){
                event.preventDefault();
                    $('#video_upload').uploadifyUpload();
            });

        }); 
</script>
<input id="video_upload" width="120" type="file" height="30" name="video[upload]">

And I have a simple videos_controller, which uses paperclip to handle file data (this works fine with normal html uploads). When I choose a file, everything works - the progress bar appears etc - but then nothing happens. There is nothing printed to the console or in the logs. I thought it was an authenticity thing, but have tried about everything on that front and still no luck... Very frustrating.

Any help would be really great.

EDIT ========

To avoid having a button to initiate the upload, which I thought was the original case, use auto: true in your uploadify config. While an oversight on my behalf it almost broke my brain.


回答1:


As mentioned in the comments above, looks like he just missed something from his sample

<input id="video_submit" type="submit" value="Upload my Video!"/>

Now his jQuery will register a click event for the video_submit button and upload the file Once clicked



来源:https://stackoverflow.com/questions/7276315/uploadify-rails-3-0-nothing-happens-after-file-is-chosen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!