On Jan 29, 2010, at 4:41 PM, Jerry Franks wrote:>
> Consider this situation: a model Person and a model State with a habtm
> association between them. A person can be associated with one or more
> States and a state can be associated with more than one person.
>
> In a web form I have a SELECT input with all the states listed. I
> create a new Person record and select three states and save. So far,
> so good.
>
> I then go back and edit the just-created record and de-select all the
> states and press save. My intuition tells me that either I should get
> a validation error or all the states should be dis-associated from the
> person. However, what _does- happen is nothing: the record does not
> change. The person still has the three states associated to him.
>
> Looking at what get''s PUT''ed I see that the
SELECT''s fieldname is not
> passed to the browser when nothing is selected, so it appears that
> Rails just assumes that if the input name does not appear in the PUT,
> then it should ignore it. Is that true?
>
> What is the recommended way to deal with this? Test for the absence of
> the input field values, and if absent delete them explicitly?
Why not change your update method to remove all associated states, period, then
add them in, as per the post data, if any. Browsers don''t typically
send empty post data.
--
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=en.