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_select(@customers, :id, :first_name)
The current HTML output is:
<option value="4">Fred</option>
But I want:
<option value="4">Fred Flintstone</option>
I want to display the full name instead of just the first name. I can't seem to get it to use both fields "first_name" and "last_name" nor can I figure out how to get it to call a method where I concatenate the two fields. How can I get this to work?
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}" }
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With