Reputation: 892
How can I add two label elements when choosing association in Simple Form on Ruby on Rails?
Sample: @user.name = "Barack"
and
@user.last_name = "Obama"
Here is my code:
<%= f.association :persona, :collection => Persona.order(:name),
:prompt => 'Choose a person' %>
It displays only Barack but I need it to display not only name
but also last_name
when choosing from list.
Upvotes: 0
Views: 55
Reputation: 4277
<%= f.association :persona, :collection => Persona.order(:name), :label_method => lambda { |persona| "#{persona.name} #{persona.last_name}" }, :prompt => 'Choose a person'%>
Here is the answer - you need a complex label_method.
Upvotes: 2