2014-09-21 50 views
0

我在我的控制器使用此:如何將這些Rails4參數白名單列表?

def step_params 
    params.require(@type.underscore.to_sym).permit( 
    :id, :name, :note, :position, :institution_id, :protocol_id, :sequence_id,:orientation_id, 
    step_item_attributes: [:id, :note, :name, :position, :institution_id, :sequence_id, :orientation_id, :_destroy ], 
    step_list_attributes: [:id, :note, :name, :position, :institution_id, :sequence_id, :orientation_id, :_destroy ]) 
end 

而且看到這個在服務器日誌與嵌套屬性的表單後提交:

Processing by StepsController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"Xm6oMMJ2PLXhHfKS1RkIzG5LrCUAY6vLOF+e9XHgBE4=", "step_list"=>{"name"=>"bob bob", "note"=>"", "step_items_attributes"=>{"1411264481612"=>{"name"=>"", "orientation_id"=>"1", "sequence_id"=>"1", "note"=>"a note", "_destroy"=>"false"}}}, "commit"=>"Create Step list", "type"=>"StepList"} 
    User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1 
Unpermitted parameters: step_items_attributes 
    (0.1ms) begin transaction 
    SQL (0.7ms) INSERT INTO "steps" ("created_at", "institution_id", "name", "note", "updated_at") VALUES (?, ?, ?, ?, ?) [["created_at", "2014-09-21 01:54:49.736556"], ["institution_id", 18], ["name", "bob bob"], ["note", ""], ["updated_at", "2014-09-21 01:54:49.736556"]] 
    (37.5ms) commit transaction 
Redirected to http://localhost:3000/steps/54 
Completed 302 Found in 47ms (ActiveRecord: 38.7ms) 

在我看來就像「不允許的參數:step_items_attributes」

...是問題所在。

爲什麼我的permit方法不允許step_items_attributes散列?我怎麼能找出其他符號可能工作?

回答

1

您允許的物品套裝step_item_attributes但您試圖通過step_items_attributes(物品)加上's'。所以這就是爲什麼你得到Unpermitted parameters: step_items_attributes

+0

哦,我的天啊。謝謝。 – 2014-09-21 14:39:52

+0

FWIW,我也在同一個控制器中創建動作時遇到了麻煩。我的錯誤是產生了錯誤的類的對象。當我不仔細閱讀時,會導致另一個類似的錯誤。解決這兩個問題的事情再次運作。謝謝。 – 2014-09-21 14:41:19

+0

oops。沒有了。我不得不按照這些有序的指示去理解:http://patshaughnessy.net/2014/6/16/a-rule-of-thumb-for-strong-parameters – 2014-09-22 18:03:59

相關問題