2013-10-03 70 views
0

請幫我弄清楚我在這裏做錯了什麼!我正在使用s3_direct_upload將基本映像上載到Amazon S3,然後使用POST創建記錄。我可以在網絡標籤(firebug)中看到它正在POST'd。但是,我不確定爲什麼params沒有被添加到數據庫中。Rails - Params未被添加到模型中?

這是我得到回:

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

''Choise'模型對'create'的期望是什麼?'require'只返回一個'{「image」=>「https:// ...」}'你的「選擇」模式是否期待這個單一領域?你的模型正在回滾 – Cristopher

回答

1

從「回滾」,它看起來像你沒有保存記錄。或許,有些驗證並沒有得到滿足。更改

@choice = Choice.create(choice_params) 

@choice = Choice.create!(choice_params) 

所以,你可以得到關於爲什麼你的記錄沒有被保存的回覆信息。

+0

就是這樣。驗證沒有得到滿足;我忘了刪除舊的不必要的驗證。 – Dodinas

相關問題