Rails在表单中选择返回索引。我想发送文本 [英] Rails Select in Form returns Index. I want to send the Text

查看:148
本文介绍了Rails在表单中选择返回索引。我想发送文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%= f.select :owner, options_for_select(names) %>

这里的名字是一个名字数组,例如哈里,巴里,乔。
表单元素将:owner的值设置为所选选项的索引,即0,1,2。
我想发送价值,即harry,barry,joe。

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?

推荐答案

[text,value]对的两个元素数组因此:

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

这篇关于Rails在表单中选择返回索引。我想发送文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆