update 完美解决 http://wuinm.com/notes/2014/01/24/selective-save-or-update-for-nested-attribute-updating-in-rails.html
= = = = = = = == == = =
类似的问题 http://stackoverflow.com/questions/3579924/accepts-nested-attributes-for-with-find-or-create
accepts_nested_attributes_for : aliases
怎么样实现创建 aliases 的时候是 find_or_create 模式,从而确保不重复创建。stackoverflow 只给出了单个的形式,而且在 mongoid 下没法实现。
有必要一定要用 nested_attributes 实现吗?
foo = Foo.create params[:foo]
params[:foo][:aliases].each { |alias_params| foo.aliases.find_or_create_by(alias_params) }
class Band
include Mongoid::Document
embeds_many :albums
accepts_nested_attributes_for :albums,
reject_if: ->(attrs){ attrs[:name] == "Violator" }
end
文档碉堡了 http://mongoid.org/en/mongoid/docs/nested_attributes.html
accepts_nested_attributes_for :XXX mongoid 必须可以用啊, <%= f.fields_for :XXX,@XXX.XXX.new(:XX => XX, :XX => XX) do |builder| %> ...