Search code examples
ruby-on-railsformtastic

Rails/Formtastic Newbie: Setting display field for referenced "select" box


New formtastic user here.

I have a relationship user has_many clients

In formtastic, if I do something such as

f.input :employer

it returns a select box of all employer object references. I'd like to display (last name, first name) instead. I'm sure this is very simple, but I can't figure out exactly how to do it.. Any help appreciated.


Solution

  • Try

    f.input :employers, :as => :select, :collection => Employer.find(:all, :order => "last_name ASC")

    or

    f.input :employers, :as => :select, :collection => Employer.collect {|e| [e.last_name, e.id] }