Search code examples
ruby-on-rails-3.2simple-form

How do I display the appropriate field in a simple form collection select?


In a Rails 3.2 app with bootstrap and simple form, I have the following in a view:

<%= simple_form_for(@invoice) do |f| %>
   <%= f.input :user_id, :collection => @users %>
   ...
<% end %>

Instead of displaying username the pull down menu displays records like so:

#<User:0X007...>

I haven't found any simple form syntax that will display the username.


Solution

  • I might use #map to grab one certain user attribute.

    <%= simple_form_for(@invoice) do |f| %>
       <%= f.input :user_id, :collection => @users.map(&:name) %>
       ...
    <% end %>