SergioMB
2009-Nov-24 00:06 UTC
Problem with association when getting a validation error on update
Quick overview: 2 classes- class Building < ActiveRecord::Base has_many :styles, :dependent => :destroy validates_presence_of :address1 accepts_nested_attributes_for :styles, :allow_destroy => true end class Style < ActiveRecord::Base belongs_to :building end The sequence of my problem is as follows: - Edit building view and retrieve is different styles (so I can manipulate them through accepts_nested_attributes_for) - I delete one of the mandatory fields in building (on testing purpose) - Using javascript I add a new style to the form so it saves on update new attribute and association - Submit update form - Validation detects an error (one mandatory field in building is missing) - Edit view is rendered with validation error And here is my problem: - The style I added before shows now is showing as if it was already saved. And it is not. - I add the missing field to building - Submit Update - I get this error: expected Array (got Hash) for param `styles_attributes'' How can I access the update object after validation fails and hasn''t been saved? Thanks a lot! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.