请帮我弄清楚我在做错了什么!我使用s3_direct_upload将基本映像上传到Amazon S3,然后POST以创建记录。我可以在网络选项卡(firebug)中看到它正在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 %>
任何帮助都会很棒!
答案 0 :(得分:1)
来自&#39; ROLLBACK&#34;,看起来您没有保存记录。也许,某些验证没有得到满足。变化
@choice = Choice.create(choice_params)
到
@choice = Choice.create!(choice_params)
这样您就可以获得有关您的记录未被保存的原因的信息。