在ruby on rails 3.1中上传时服务器错误



我正在尝试使用uploadify和回形针在rail 3.1上上传视频

当我用uploadify上传视频时,服务器返回一个500错误。development.log显示:

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'.

这是我的控制器

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

这是我的上传器:

    <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);
    }
});

任何想法?

这个错误非常简单——它说你缺少一个呈现videos/create的模板——如果你想在这里呈现HTML,你需要创建这个模板。如果您期望JSON响应,则需要弄清楚为什么没有触发JSON响应。将'script'参数更改为'/videos '。json'应该负责这个,尽管使用Rails帮助器url_for.

可能更聪明。

最新更新