I was discussing this with Rupert on irc, and we thought, that it maybe is the best option to "remember" the nested attributes that couldn't be saved in some ivar on the resource. This way, a failing create action that renders the :new form, should have the already POSTed information available, and thus be able to rebuild the form to the same state that it was in before it got POSTed to the server. Rupert is kind enough to work on this in his fork, thx again Rupert!
On Mon, Apr 13, 2009 at 19:33, Rupert Voelcker <[email protected]> wrote: > >> Any help, ideas, discussions on irc/email, forks, patches, whatever >> ... are really appreciated! > > This time to the mailing list (and to the right mailing list!) > > OKay ....played some more - not sure if this is in nested attributes > territory or not but here's my setup: > > class Team > has n, :team_memberships, :class_name => "TeamMember" > has n, :team_members, :through => :team_memberships, > :class_name => "User", > :child_key => [:team_id], > :remote_name => :user, > > accepts_nested_attributes_for :team_memberships > end > > class TeamMember > belongs_to :team > belongs_to :user > end > > class User > has n, :team_memberships, :class_name => "TeamMember" > end > > Then on a form for creating a team I have dropdowns for selecting the > team member names which result in the following attributes being sent > back to the Team model: > > Team.new({"name"=>"adds", > "team_memberships_attributes"=>[{"user_id"=>"5"}, {"user_id"=>"42"}], > "short_name"=>""} > ) > > Now if the validation fails on the team model (cause the short_name > has been left blank) then I can't see how to recover the selections > made for the team memberships so that when the form is re-displayed > with errors it looks like it did when it was submitted. > > Any thoughts??? > > Cheers > > Rupert > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
