【问题标题】:server error with uploadify in ruby on rails 3.1ruby on rails 3.1中的uploadify服务器错误
【发布时间】:2011-10-04 13:39:46
【问题描述】:

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

当我使用 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);
    }
});

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails-3 paperclip uploadify missing-template


    【解决方案1】:

    这个错误很简单——它是说你缺少一个模板来渲染videos/create——如果你想在这里渲染HTML,你需要创建这个模板。如果您希望得到 JSON 响应,则需要弄清楚为什么没有触发它。将 'script' 参数更改为 '/videos.json' 应该可以解决这个问题,尽管使用 Rails 帮助程序 url_for 可能更聪明。

    【讨论】:

    • 谢谢你的回答,这是我第一次使用rails。但是正如你所看到的,我对 papeclip 有另一个问题,logger.info(@video.inspect) 显示所有参数为零。可能是什么原因?
    • 您的创建操作正在寻找 params[:video] 中的数据,但您并没有以这种方式提交数据。我对 uploadify 了解的不够多,而且您还没有在此处包含整个表单,但我认为您需要执行 form_for(:video, etc) 之类的操作来解决此问题。
    猜你喜欢
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 2011-01-14
    • 2015-02-23
    • 2011-10-12
    • 2012-07-31
    • 2020-06-04
    • 2014-06-09
    相关资源
    最近更新 更多