I have the following in a select_tag. It works fine. (I\'m using select_tag because it is for a search not tied to a model.)
options_from_collection_for_sele
You can define on your model:
def name; "#{first_name} #{last_name}";end
and use:
options_from_collection_for_select(@customers, :id, :name)
This can also be done in this way, you don't need to write a method in your model.
options_from_collections_for_select(
@customers, :id, ->(ob) { "#{ob.first_name} #{ob.last_name}" }
)
add method full_name in your model :
def full_name
"#{first_name} #{last_name}"
end
and use this :
options_from_collection_for_select(@customers, :id, :full_name)
Hope this will help.