14 Jun '13, 6pm

Validation errors using accepts_nested_attributes_for? Try adding inverse_of

accepts_nested_attributes_for with Has-Many-Through Relations If you find yourself getting validation errors when using accepts_nested_attributes_for with has-many-through relations, the answer may be to add an inverse_of option. The inverse_of option allows you to tell Rails when two model relations describe the same relationship, but from opposite directions. For example, if a User has_many :posts and a Post belongs_to :user , you can tell Rails that the :user relation on Post is the inverse of the :posts relation on User . This option is usually not required, but there are cases where it matters. One such case is when using accepts_nested_attributes_for with a has-many-through relation. This will eventually lead to a collection= assignment which is only possible if Rails knows that one relation is the inverse of another. Example In our case, we had the following three m...

Full article: http://robots.thoughtbot.com/post/52960938209/accepts-nes...

Tweets