Thx for the info snusnu! On Mar 16, 10:54 pm, Martin Gamsjaeger <[email protected]> wrote: > George, > > I need to revisit dana (dm-accepts_nested_attributes) soon anyway, > because I want to make it so that it *just works* with rails (I'm in > the process of switching a larger app to rails3). I gotta admit that I > haven't tried to run the specs in a while. In the meantime, I > encourage you to dive into the code and see what's going on and where. > It's really not complicated imho, and it could provide insight into > why it's behaving the way it does. > > Sorry I got no more specific advice atm, but I can promise that I will > do what needs to be done to have it compatible/usable with latest dm > codes, soon. > > cheers > snusnu > > On Tue, Mar 16, 2010 at 23:17, George <[email protected]> > wrote: > > BTW As snusnu suggested I also tried calling @trip.attributes(trip) > > followed by @trip.save (in the controller's create action), but the > > call to attributes() triggered the same old dirty resource error as > > the update method. > > > There is no code that modifies the object before calling save or > > update. It just receives fields submitted from a form. > > > Is there a correct way to use the nested_attributes plugin? If DM is > > *meant* to raise the dirty resource error then how do you work around > > it or fix it in order to make the plugin usable? > > > Many thanks > > George > > > On Mar 15, 12:04 pm, George <[email protected]> wrote: > >> Thanks snusnu. > > >> Interestingly, nothing is modifying the attributes before save or > >> update. > > >> When the submitted form contains associated fields such as > >> trip[trip_clients_attributes][0][is_invoicable] then we get the dirty > >> resource error. > > >> Here's an example of submitted params: > > >> merb : worker (port 81) ~ Params: {"_method"=>"put", > >> "trip"=>{"version_of_trip_id"=>"94154", "name"=>"A lovely new trip2", > >> "start_date"=>"03/10/2010", "user_id"=>"99", "adults"=>"1", > >> "end_date"=>"03/10/2010", "company_id"=>"1", "children"=>"0", > >> "type_id"=>"1", "infants"=>"0", > >> "trip_clients_attributes"=>{"0"=>{"id"=>"54198", "is_single"=>"0", > >> "is_primary"=>"1", "is_invoicable"=>"1"}, "1"=>{"id"=>"54215", > >> "is_single"=>"1", "is_primary"=>"0", "is_invoicable"=>"1"}}}, > >> "client_id"=>"2138471587", "group_id"=>"4", "submit"=>"Save changes", > >> "controller"=>"trips", "action"=>"update", "id"=>"94154", > >> "format"=>nil} > > >> Controller action: > > >> def update(id, trip) > >> @trip = Trip.get(id) > >> raise NotFound unless @trip > >> if @trip.update(trip) > >> ... > > >> On Mar 13, 1:21 am, Martin Gamsjaeger <[email protected]> wrote: > > >> > George, > > >> > Calling #update on a dirty resource indeed raises an error and that is > >> > the expected dm behavior (it's got nothing to do with my plugin). If > >> > you find yourself updating the attributes of a resource in different > >> > places before persisting it, you should use #save instead of #update. > >> > This is probably confusing to some people, because #update only > >> > started to raise that error with recent versions of dm. I'm not sure > >> > if it was introduced in 0.10.1 or 0.10.2, but iirc, it wasn't present > >> > in 0.10.0 and definitely not in 0.9.x. > > >> > cheers > >> > snusnu > > >> > On Fri, Mar 12, 2010 at 16:43, George <[email protected]> > >> > wrote: > >> > > Am using snusnu's excellent "dm-accepts_nested_attributes" plugin but > >> > > getting an error when submitting a form to update a "Trip" object: > > >> > > "Update Conflict Error 500 TripClient#update cannot be called on a > >> > > dirty resource" > > >> > > trips are related to clients through trip_clients > >> > > and the Trip model accepts_nested_attributes_for :trip_clients > >> > > (to allow a couple of extra fields to be set on each association, such > >> > > as 'is_invoicable') > > >> > > It saves fine if I only save changes to fields in trip_clients, but > >> > > the error crops up if I also submit changes to the trip object at the > >> > > same time. > > >> > > Any ideas why? > > >> > > Many thanks, > >> > > George > > >> > > -- > >> > > 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 > >> > > athttp://groups.google.com/group/datamapper?hl=en. > > > -- > > 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 > > athttp://groups.google.com/group/datamapper?hl=en. > >
-- 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.
