# Select input with nothing selected does not delete

**URL:** <https://www.ruby-forum.com/t/select-input-with-nothing-selected-does-not-delete/182581>\
**Category:** Rails\
**Created:** [January 30, 2010, 11:10am UTC](https://www.ruby-forum.com/t/select-input-with-nothing-selected-does-not-delete/182581 "2010-01-30T11:10:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerry\_Franks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/46a35a/32.png) [@Jerry\_Franks](https://www.ruby-forum.com/u/Jerry_Franks)\
**Post date:** [January 30, 2010, 11:10am UTC](https://www.ruby-forum.com/t/select-input-with-nothing-selected-does-not-delete/182581/1 "2010-01-30T11:10:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jerry\_Franks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/46a35a/32.png) [@Jerry\_Franks](https://www.ruby-forum.com/u/Jerry_Franks)\
**Post date:** [January 30, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/select-input-with-nothing-selected-does-not-delete/182581/2 "2010-01-30T20:30:43Z")

</div>

On Jan 29, 2010, at 4:41 PM, Jerry Franks wrote:

> states and press save. My intuition tells me that either I should get  
> 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.
