开发者

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

开发者 https://www.devze.com 2023-03-20 06:16 出处:网络
<%= f.select :owner, options_for_s开发者_运维技巧elect(names) %> Here names is an array of names e.g. \"harry\", \"barry\", \"joe\".
<%= 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

精彩评论

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