0

请帮我弄清楚我在这里做错了什么!我正在使用 s3_direct_upload 将基本图像上传到 Amazon S3,然后 POST 以创建记录。我可以在“网络”选项卡(萤火虫)中看到它正在发布。但是,我不确定为什么没有将参数添加到数据库中。

这就是我要回来的:

   Started POST "/choices" for 127.0.0.1 at 2013-10-02 17:36:10 -0700
   Processing by ChoicesController#create as */*
   Parameters: {"url"=>"https://mybucket.s3.amazonaws.com/uploads%2F1380760569802-bneiuk2ghf4-22e59d1c8959be731bc71e31f0a9d7c6%2Fslide0003_image002.jpg",        
   "filepath"=>"/uploads%2F1380760569802-bneiuk2ghf4-22e59d1c8959be731bc71e31f0a9d7c6%2Fslide0003_image002.jpg", 
   "filename"=>"slide0003_image002.jpg", 
   "filesize"=>"73930", 
   "filetype"=>"image/jpeg", 
   "unique_id"=>"bneiuk2ghf4", 
   "choice"=>{
      "image"=>"https://mybucket.s3.amazonaws.com/uploads%2F1380760569802-bneiuk2ghf4-22e59d1c8959be731bc71e31f0a9d7c6%2Fslide0003_image002.jpg"
    }
   }
   (0.3ms)  BEGIN
   (0.4ms)  ROLLBACK
  Rendered choices/create.js.erb (0.1ms)
  Completed 200 OK in 16ms (Views: 6.2ms | ActiveRecord: 0.6ms)

 

 # app/controllers/choice.rb
  def create
   @choice = Choice.create(choice_params)
  end

 def choice_params
   params.require(:choice).permit!
 end

然后是我的表单(为简洁起见,省略了一些 HTML):

#app/views/new.html.erb
   <%= s3_uploader_form callback_url: choices_url, callback_param: "choice[image]", id: "s3-uploader" do %>
      <%= file_field_tag :file, multiple: true %>
   <% end %>

任何帮助都会很棒!

4

1 回答 1

1

从“ROLLBACK”来看,您似乎没有保存记录。也许,一些验证没有得到满足。更改

@choice = Choice.create(choice_params)

@choice = Choice.create!(choice_params)

这样您就可以获取有关为什么您的记录没有被保存的信息。

于 2013-10-03T18:06:33.217 回答