1

I'm trying to upload a video using uploadify and paperclip on rail 3.1

When i upload a video with uploadify, the server returns an 500 error. The development.log says:

Started POST "/videos" for 127.0.0.1 at Tue Oct 04 14:46:05 +0200 2011
Processing by VideosController#create as HTML
Parameters: {"Filename"=>"prova.mov", "folder"=>"/public",...}
WARNING: Can't verify CSRF token authenticity
#<Video id: nil, source_content_type: nil, source_file_name: nil, source_file_size:nil, state: nil, created_at: nil, updated_at: nil>
[paperclip] Saving attachments.
Completed 500 Internal Server Error in 29ms
ActionView::MissingTemplate (Missing template videos/create, application/create with {:locale=>[:en, :en], :handlers=>[:builder, :coffee, :erb], :formats=>[:html]}. Searched in:
* "($mypath)/workspace/Video_Api/app/views"):app/controllers/videos_controller.rb:48:in `create'.

This is my controller:

def create
 logger.info(params.inspect)
 @video = Video.new(params[:video])

 logger.info(@video.inspect)

 respond_to do |format|
  if @video.save
    format.html 
    format.json { render :json => @video, :status => :created, :location => @video }
  else
    format.html { render :action => "new" }
    format.json { render :json => @video.errors, :status => :unprocessable_entity }
  end
 end
end

And this is my uploader:

    <input id="upload" type="file" name="upload" />
    <!--div class="button" id="send_button">SEND FILE</div -->
</div>
<script>
 <%- session_key = Rails.application.config.session_options[:key] -%>

$('#upload').uploadify({
    'uploader'  : 'uploadify.swf',
    'script'    : '/videos',
    'cancelImg' : 'images/cancel.png',
    'folder'    : '/public',
    'buttonText'  : 'Add video!',
    'multi'     : true,
    'auto'      : true,
    'scriptData' : {"<%= key = Rails.application.config.session_options[:key] %>" :"<%= cookies[key] %>",
        "<%= request_forgery_protection_token %>" : "<%= form_authenticity_token %>",
    },
    onError : function (event, id, fileObj, errorObj) {
        alert("error: " + errorObj.info);
    }
});

Any ideas?

pnuts
  • 58,317
  • 11
  • 87
  • 139
daniel
  • 41
  • 3

1 Answers1

0

The error is pretty straightforward -- it is saying that you are missing a template to render videos/create -- if you're trying to render HTML here, you'll need to create this template. If you're expecting your JSON response instead, you need to figure out why that isn't being triggered. Changing the 'script' parameter to be '/videos.json' should take care of that, although it might be smarter to use the Rails helper url_for.

muffinista
  • 6,676
  • 2
  • 30
  • 23
  • Thank you for the answer, it's my first time with rails. But as you can see, i have another issue with papeclip, the logger.info(@video.inspect) shows nil for all parameters. which may be the reason? – daniel Oct 05 '11 at 16:38
  • Your create action is looking for data in params[:video], but you're not submitting your data that way. I don't know enough about uploadify, and you haven't included your entire form here, but I assume you need to do something like form_for(:video, etc) to fix this. – muffinista Oct 05 '11 at 16:46