【问题标题】:Rails options_for_select / ActiveRecord_Associations_CollectionProxyRails options_for_select / ActiveRecord_Associations_CollectionProxy
【发布时间】:2014-04-25 12:03:03
【问题描述】:

我正在尝试获取 current_user.albums 以显示在 select 列表中。

<% album_options = current_user.albums { |a| [a.title, "#{a.title}-Album"] } %>

<%= select :screen, :attachable_id, options_for_select(album_options) %>

但我得到的输出是:

<select id="screen_attachable_id" name="screen[attachable_id]">
  <option value="#<Album:0x007fe77bacf2a0>">#&lt;Album:0x007fe77bacf2a0&gt;</option>
</select>

我错过了什么?

【问题讨论】:

    标签: ruby-on-rails forms select ruby-on-rails-4


    【解决方案1】:

    你忘了map

    <% album_options = current_user.albums.map { |a| [a.title, "#{a.title}-Album"] } %>
    

    【讨论】:

    • 大声笑... :D.. 完全忘记了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多