开发者

Rails Select in Form returns Index. I want to send the Text

<%= f.select :owner, options_for_s开发者_运维技巧elect(names) %>

Here names is an array of names e.g. "harry", "barry", "joe". The form element sets value of :owner to the index of the selected option i.e. 0,1,2. I want to send the value instead i.e. "harry", "barry", "joe".

Is there an option for select that will do so? If not, how can I achieve this?


Map name in a two element array of [text,value] pairs thus:

<%= f.select :owner, options_for_select(names.map {|name| [name,name]}) %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜