Storing a Selected Option in DB

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

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