开发者

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

开发者 https://www.devze.com 2023-03-05 01:19 出处:网络
I have this code: <%= f.label :lang%><br /> <%= f.select :lang_id, @langs %> it generates html like that:

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开发者_如何学Python />
<%= f.select :lang_name, @langs %>

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


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], ....]
0

精彩评论

暂无评论...
验证码 换一张
取 消