ruby on Rails 3.1 中的 uploadify 服务器错误

发布于 2024-12-08 00:47:23 字数 2218 浏览 1 评论 0 原文

我正在尝试在 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);
    }
});

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月竹挽风 2024-12-15 00:47:23

该错误非常简单 - 它表示您缺少渲染 videos/create 的模板 - 如果您尝试在此处渲染 HTML,则需要创建此模板。如果您期望 JSON 响应,则需要弄清楚为什么没有被触发。将 'script' 参数更改为 '/videos.json' 应该可以解决这个问题,尽管使用 Rails 帮助器 url_for

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文