# form select not saving to the database

**URL:** <https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355>\
**Category:** rubyonrails-talk\
**Created:** [June 15, 2010, 3:48pm UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355 "2010-06-15T15:48:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 15, 2010, 3:48pm UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355/1 "2010-06-15T15:48:31Z")

</div>

\<%= f.label :type %\> \<%= f.select(:type, ["original","print","other"]) %\>

I have a photos model and added a drop-down list to the form, when the option is selected, the correct parameters are passed but it is not saved to the database. I've googled this and looked at the api but I'm not sure what I'm doing. In my photo model type is a string.

Is string the wrong field type? or anything else wrong?

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [June 15, 2010, 3:51pm UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355/2 "2010-06-15T15:51:47Z")

</div>

> \<%= f.label :type %\> \<%= f.select(:type, ["original","print","other"]) %\>
> 
> I have a photos model and added a drop-down list to the form, when the option is selected, the correct parameters are passed but it is not saved to the database. I've googled this and looked at the api but I'm not sure what I'm doing. In my photo model type is a string.
> 
> Is string the wrong field type? or anything else wrong?

If an attribute is named type Active Record will try and use it for single table inheritance.

Fred

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 15, 2010, 10:17pm UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355/3 "2010-06-15T22:17:27Z")

</div>

the batman wrote:

> \<%= f.label :type %\> \<%= f.select(:type, ["original","print","other"]) %\>
> 
> I have a photos model and added a drop-down list to the form, when the option is selected, the correct parameters are passed but it is not saved to the database. I've googled this and looked at the api but I'm not sure what I'm doing. In my photo model type is a string.
> 
> Is string the wrong field type? or anything else wrong?

You've omitted the essential information to diagnose the problem. What's the form action? Are your routes correct? What shows in the log as being posted in params? Are there any error messages?

Best,

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 15, 2010, 11:03pm UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355/4 "2010-06-15T23:03:21Z")

</div>

the batman wrote:

> \<%= f.label :type %\> \<%= f.select(:type, ["original","print","other"]) %\>
> 
> I have a photos model and added a drop-down list to the form, when the option is selected, the correct parameters are passed but it is not saved to the database. I've googled this and looked at the api but I'm not sure what I'm doing. In my photo model type is a string.
> 
> Is string the wrong field type? or anything else wrong?

Oh, disregard my earlier post. I just realized what's going on. Rails reserves the field name "type" for STI purposes, and gets confused if you try to use that name for an ordinary field.

Best,

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [June 16, 2010, 8:40am UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355/5 "2010-06-16T08:40:22Z")

</div>

Marnen Laibow-Koser wrote:

> the batman wrote:
> 
> > \<%= f.label :type %\> \<%= f.select(:type, ["original","print","other"]) %\>
> > 
> > I have a photos model and added a drop-down list to the form, when the option is selected, the correct parameters are passed but it is not saved to the database. I've googled this and looked at the api but I'm not sure what I'm doing. In my photo model type is a string.
> > 
> > Is string the wrong field type? or anything else wrong?
> 
> Oh, disregard my earlier post. I just realized what's going on. Rails reserves the field name "type" for STI purposes, and gets confused if you try to use that name for an ordinary field.
> 
> Best, -- Marnen Laibow-Koser [http://www.marnen.org](http://www.marnen.org) marnen@marnen.org

I recently encountered this same problem. I simply changed the column to 'category' and solved the problem. Though, it took far too long for me to realise this.

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [June 16, 2010, 4:14pm UTC](https://discuss.rubyonrails.org/t/form-select-not-saving-to-the-database/52355/6 "2010-06-16T16:14:41Z")

</div>

This is a useful page to refer to when strange things are going on that do not seem to make sense. [http://wiki.rubyonrails.org/rails/pages/ReservedWords](http://wiki.rubyonrails.org/rails/pages/ReservedWords)

Colin
