开发者

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开发者_如何学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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜