开发者

Formtastic label_method

开发者 https://www.devze.com 2023-03-22 23:00 出处:网络
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 => c

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} #{:forma开发者_如何学Got}", :as => :select, :collection => Isbn.order("name ASC").where(:client_id => current_user.client_id).all %>

But of course it doesn't.


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 ??

0

精彩评论

暂无评论...
验证码 换一张
取 消