# Storing a Selected Option in DB

**URL:** <https://www.ruby-forum.com/t/storing-a-selected-option-in-db/76855>\
**Category:** Rails\
**Created:** [March 5, 2006, 8:16am UTC](https://www.ruby-forum.com/t/storing-a-selected-option-in-db/76855 "2006-03-05T08:16:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 5, 2006, 8:16am UTC](https://www.ruby-forum.com/t/storing-a-selected-option-in-db/76855/1 "2006-03-05T08:16:54Z")

</div>

OK, thanks to Kelly I got my options\_for\_select in a select\_tag  
helper method to use a Ruby range as a value. Now when the user makes  
a selection from that list, I can’t figure out why the result doesn’t  
get stored in the database.

The line in the \_form looks like this:  
\<%= select\_tag(:month, options\_for\_select((0…12).to\_a)) %\>

Pops up an option menu. There’s a column in the database called  
“month.” It’s defined as an integer. So I would expect Rails just to  
take the user’s selection and stuff it into that column of the table.  
But nothing gets placed there at all.

I’m obviously missing something. I went into irb and typed:

x = (1…12).to\_a  
[1 2 3 4 5 6 7 8 9 10 11 12]  
x[3].integer?  
=\>true

So I am pretty sure the array holds integers. What’s the missing link?

Dan

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 6, 2006, 3:28am UTC](https://www.ruby-forum.com/t/storing-a-selected-option-in-db/76855/2 "2006-03-06T03:28:02Z")

</div>

Dan S. wrote:

> user’s selection and stuff it into that column of the table. But nothing  
> gets placed there at all.
> 
> I’m obviously missing something. I went into irb and typed:
> 
> x = (1…12).to\_a  
> [1 2 3 4 5 6 7 8 9 10 11 12]  
> x[3].integer?  
> =\>true
> 
> So I am pretty sure the array holds integers. What’s the missing link?

Hi Dan

You’ve showed us a little bit of what’s happening in your view, and told  
us that there is a column in the database called ‘month’.

What table is that in, what does the model look like, and what action is  
this form being submitted to in your controller?

Do you have the Agile Web D. with Rails book? Have you read the  
section on form helpers (section 17.8)? If you are expecting the value  
to go straight into the database, it will have to get there via a model,  
and you should probably be using the select helper rather than the  
select\_tag helper.

Anyway, send more info… but I won’t be able to follow up until this  
(Monday) evening, UK time.

regards

Justin
