Hi all,
This question is about getting delete to work on nested models during an
update on the parent object.
I'm using a jquery datepicker to allow users to add and remove multiple
dates (bookings) from a parent object (room). Adding dates to the parent
object is easy. The jquery datepicker gives me a function that gets called
whenever the user clicks on a date. Within this function, I can build a
hidden input that looks like this within the page:
<input type="hidden" value="12/04/2009" name="room
[bookings_attributes][][date]"/>
Then within the controller, with the help of nested models, the call to
@room.update_attributes(params[:room]) knows to create the bookings as
well.
My question, is how can I build an input tag in the html that will tell the
controller to remove an existing booking if the user unselects a previously
saved booking from within the calendar?
if I build one like this:
<input type="hidden" value="12/12/2009" name="room
[bookings_attributes][][_delete]"/>
then, the parameters get passed like this:
Parameters: {"commit"=>"Update Reservation", "authenticity_token"=>"blah",
"id"=>"11", "room"=>{"bookings_attributes"=>[{"_delete"=>"12/12/2009"}]}}
And then the following sql happens:
SELECT "bookings".id FROM "bookings" WHERE ("bookings"."date" IS NULL AND
"bookings".room_id = 11) LIMIT 1
Which isn't right. I'm thinking maybe I need two input tags? One to
identify the booking that I'm removing and the other to tell the controller
to delete it? Any help on how this should work would be appreciated. I
could also do this the long way and just create separate and unrelated input
tags and put the intelligence for deleting into my controller, but i feel
like nested models should give me this for free...
Thanks in advance,
--Jon
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---