【问题标题】:Rails Select in Form returns Index. I want to send the TextRails Select in Form 返回索引。我想发送文本
【发布时间】:2011-10-03 20:12:28
【问题描述】:
<%= f.select :owner, options_for_select(names) %>

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

有没有这样的选择选项?如果没有,我该如何实现?

【问题讨论】:

    标签: ruby-on-rails forms select text indexing


    【解决方案1】:

    two element array of [text,value] pairs 中的映射名称因此:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多