s3直接上传方法错误

时间:2015-02-16 22:36:33

标签: ruby-on-rails ruby-on-rails-4 amazon-s3

我使用此gem将文件直接上传到S3

gem 's3_direct_upload'

https://github.com/waynehoover/s3_direct_upload

_form.html.erb

<%= s3_uploader_form callback_url: polymorphic_url([@academy, :dashboard,  @course, @lesson], {only_path: false}),callback_method: "PATCH", callback_param: "lesson[media]", id: "s3-uploader" do %>
    <%= file_field_tag :file, multiple: true %>
  <% end %>

  <script id="template-upload" type="text/x-tmpl">
  <div id="file-{%=o.unique_id%}" class="upload">
    {%=o.name%}
    <div class="progress"><div class="bar" style="width: 0%"></div></div>
  </div>
  </script>

文件已成功加载

enter image description here

但是,在进度条完成后,我在控制台日志中看到此错误:

PATCH http://localhost:3000/academies/1/dashboard/courses/1/lessons/3/edit 404 (Not Found)

控制器

class Dashboard::LessonsController < ApplicationController
  before_action :set_lesson, only: [:show, :edit, :update, :destroy, :comment]
  before_filter :authenticate_user!

    # PATCH/PUT /lessons/1
  # PATCH/PUT /lessons/1.json
  def update
    respond_to do |format|
      if @lesson.update(lesson_params)
        format.html { redirect_to [:edit, @academy,  :dashboard, @course, @lesson], notice: 'Lesson was successfully updated.' }
        format.json { render :show, status: :ok, location: @lesson }
      else
        format.html { render :edit }
        format.json { render json: @lesson.errors, status: :unprocessable_entity }
      end
    end
  end

end

3 个答案:

答案 0 :(得分:2)

通过:edit请求更新后,您会重定向到PATCH操作,如果我没错,您的:edit操作可能只接受GET请求

我不知道routes.rb#edit是如何设置的,但您可以尝试修改_form.html.erb文件的第一行,然后更改{ {1}}至callback_method: "PATCH"

答案 1 :(得分:1)

这是404,所以它试图点击使用callback_url选项配置的网址,但找不到它。

当您在该控制器中没有编辑操作时,您的回调网址(显然)已配置为/academies/1/dashboard/courses/1/lessons/3/edit

您需要将callback_url更改为指向(如评论所说).../lessons/3,而不是.../lessons/3/edit/

答案 2 :(得分:1)

问题在于Carrierwave。我不得不禁用Carrierwave,一切正常