views:

184

answers:

2

The following produces a working select drop down that pulls from my user model:

<%= f.collection_select(:user_id, @users, :id, :firstname, options ={:prompt => "Select a User"} %>

I also have a column :lastname.

I am trying to populate the select with something like :firstname + " " + :lastname

This obviously fails if I just stick it in where :firstname is. How would you go about concatenating the two columns and populating the select box.

Thanks.

+2  A: 

define a method full_name on the User model and then use :full_name in the collection select

Ben Hughes
+4  A: 

In your user model create a new method called name. Then use it in your helper.

class User

  def name
    "#{firstname} #{last_name}"
  end

end

<%= f.collection_select(:user_id, @users, :id, :name, :prompt => "Select a User") %>
Simone Carletti