ciembor
ciembor

Reputation: 7337

f.select helper - how to pass value other than id

I have this code:

<%= f.label :lang  %><br />
<%= f.select :lang_id, @langs %>

it generates html like that:

<label for="entry_lang">Lang</label><br /> 
<select id="entry_lang_id" name="entry[lang_id]">
  <option value="pl">1</option>
  <option value="en">2</option>
</select> 

Now I want to have "pl" and "en" visible for user, not integers. So I tried:

<%= f.label :lang  %><br />
<%= f.select :lang_name, @langs %>

And it doesn't work. How to do it right?

Upvotes: 0

Views: 156

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124419

It looks like your @langs array is in the format:

[[1, "pl"], [2, "en"], ....]

It should be the other way around; display name first, then id:

[["pl", 1], ["en", 2], ....]

Upvotes: 1

Related Questions