Search code examples
formslistvariablesruby-on-rails-3.1formtastic

Ruby on Rails Formtastic Multiple Options in Member_Label


I have a relational model where users have managers that are also users. The below code works great and does exactly what it's suppose to, but it's only displaying the first name of the manager. I'm trying to get this to show both the first name and the last name of the manager.

<%= sf.input :managers, :as => :check_boxes, :member_label => (:firstname)  ,:input_html => { :size => 20, :multiple => true}%>

The other field i'm trying to add is the :lastname. I cannot figure out how to get :member_label to take both fields.

enter image description here


Solution

  • I figured it out. By using the Proc.new, I was able to add in both first name and last name.

    <%= sf.input :managers, :as => :check_boxes, :member_label => Proc.new { |t| h(t.firstname + " " + t.lastname) }  ,:input_html => { :size => 20, :multiple => true}%>