Adding a related value

I have a select with values of company names. But I use the id from that
table in the select list in the form, not names. I get it with:

@userlist = User.find(:all, :order => “company”).map { |s|
[s.company,s.id]}

If I want to get the company name, also in that table, how do I do that?
Can I have a hidden field and tell that to get the company name from the
selected id of @userlist directly? Or should I have something in the
following action where the record is created, picking up the company
name?

I hope you understand. I have some problem with the logic here :slight_smile: In
php I would normally have a mysql select in the action after the form to
get the selected value. However, I have a feeling that there is a
smarter way in RoR.

Pål Bergström wrote:

I have a select with values of company names. But I use the id from that
table in the select list in the form, not names. I get it with:

@userlist = User.find(:all, :order => “company”).map { |s|
[s.company,s.id]}

I guess I must be able to get it from the created array as
“s.company,s.id”. Can this be right?

The select looks like:

<%= select(‘group’, ‘user_id’, @userlist ) %>

So can I should be able to get the value by:

@userlist[@group.user_id]

And then add that in a hidden field.

<%= hidden_field ‘group’, ‘name’, ‘?’%>

But not sure how to write it correctly.