在控制器中,我試圖訪問深度嵌套的參數。這是我的參數跟蹤。如何訪問Rails中的嵌套參數
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"2j+Nh5C7jPkNOsQnWoA0wtG/vWxLMpyKt6aiC2UmxgY=",
"inventory"=>{"ingredients_attributes"=>{"0"=>{"ingredient_name"=>"Bread"}},
"purchase_date"=>"11",
"purchase_price"=>"11",
"quantity_bought"=>"11"},
"commit"=>"Create Inventory"}
我想從這個檢索 「麪包」。我試過params[:inventory][:ingredient][:ingredient_name]
和其他變化。什麼是正確的styntax?
如果它的事項,
Inventory has_many :ingredients
Inventory accepts_nested_attributes_for :inventories
謝謝!
http://stackoverflow.com/questions/14083654/elegantly-extracting-all-strings-from-an-arbitrarily-deep-hash - 也許這將幫助? – MC2DX 2013-04-18 02:46:35