Rails options_for_select / ActiveRecord_Associations_CollectionProxy

时间:2014-04-25 12:03:04

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

我尝试抓取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>

我缺少什么?

1 个答案:

答案 0 :(得分:4)

您忘记了map

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