How to access nested params

前提是你 提交于 2019-11-30 08:56:14

To access the nested fields from params do the following:

params[:order][:items_attributes].values.each do |item|
  item[:type_id]
end if params[:order] and params[:order][:items_attributes]

Above solution will work ONLY if you have declared the correct associations and accepts_nested_attributes_for.

class Order < ActiveRecord::Base
  has_many :items
  accepts_nested_attributes_for :items, :allow_destroy => true
end

class Item < ActiveRecord::Base
  belongs_to :order
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!