【问题标题】:Form selecting from array从数组中选择表格
【发布时间】:2019-12-08 05:52:25
【问题描述】:

如何从数组中输入值而不是将它们输入到 f.select 中。我想更改它的原因是因为选项列表现在根据其他值更改。

我有一个叫做优秀的东西,我想把每个优秀的东西放到可以选择的东西列表中。

@outstandings.each go into the f.select

或类似的东西。谢谢。

<div class = "well">
   <%= form_for @userupload, html: { multipart: true } do |f| %>
      <%= f.label :nealname, "Neal's Name" %>
      <%= f.select :nealname, ['One Time','As Needed', 'Quarterly', 'Yearly'] %>
      <%= f.submit "Save", class: "btn btn-primary" %>
   <% end %>
</div>

【问题讨论】:

    标签: html ruby forms


    【解决方案1】:

    您可以将此数组作为第二个参数传递给f.select

    <%= f.select :nealname, @outstandings %>
    

    或者如果你想用动态值扩展一些静态值,你可以这样做:

    <%= f.select :nealname, ['One Time','As Needed', 'Quarterly', 'Yearly', *@outstandings] %>
    

    注意,在第二个示例中,您可以将 *@outstandings 移动到数组的开头或任何静态值之间。

    【讨论】:

      【解决方案2】:

      我认为你可以这样做

      您可以将 .name 更改为 .date 或 .whateveryouwant

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-06
        • 1970-01-01
        • 1970-01-01
        • 2011-10-20
        • 2015-10-07
        • 1970-01-01
        相关资源
        最近更新 更多