1

I'm trying to simply display 2 fields (first name and last name) in a form select (f.select). Here is my code:

<%= f.select :person, User.where(verified_person: 't').pluck(:first_name, :last_name) %>

With the code above, the select drop-down field only displays first name. I'm using Active Record 4.2 and Rails 4. Any help?

gitastic
  • 516
  • 7
  • 26

2 Answers2

0

Try Using This Code:

<%=f.select :person, options_for_select(User.where(verified_person: 't').collect {|user| ["#{user.first_name} - #{user.last_name}", user.first_name] }), :include_blank => true%>
kajal ojha
  • 1,248
  • 8
  • 20
0

I ended up using this.. seems to work for me:

<%= f.select(:person) do %>
  <% User.where(verified_person: 't').each do |user| -%>
    <%= content_tag(:option, user.first_name + " " + user.last_name, value: user.id) %>
  <% end %>
<% end %>     
gitastic
  • 516
  • 7
  • 26