Search code examples
ruby-on-railsformtastic

Formtastic label_method


Can you use two values in a Formtastic label_method?

This:

<%= f.input :isbn_id, :label_method => :name, :as => :select, :collection => Isbn.order("name ASC").where(:client_id => current_user.client_id).all %>

produces this drop down menu:

Adept
Adept
Red Men
Red Men
Blue Handbag

But I'd like this:

Adept pbk
Adept hb
Red Men pbk
Red Men hb
Blue Handbag hb

So I'd like this to work:

<%= f.input :isbn_id, :label_method => "#{:name} #{:format}", :as => :select, :collection => Isbn.order("name ASC").where(:client_id => current_user.client_id).all %>

But of course it doesn't.


Solution

  • Why don't you add a method to your model say formatted_name that returns the string "#{name} #{format}" and call at the formtastic helper :label_method => :formatted_name ??