Forum: Ruby on Rails Storing a Selected Option in DB

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
205bc8d44e9bc5c68d77dd412abcb3ce?d=identicon&s=25 Dan Shafer (Guest)
on 2006-03-05 08:16
(Received via mailing list)
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
Eea7ad39737b0dbf3de38874e0a6c7d8?d=identicon&s=25 Justin Forder (Guest)
on 2006-03-06 03:28
(Received via mailing list)
Dan Shafer 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 Development 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
This topic is locked and can not be replied to.