Rails howto: custom value field in collection_select
Very easy this one:
Contact.rb ( Model )
...
def name_and_company
@name_and_company = name + " - " + contact.company.name
end
...
Usage ( note the use of :name_and_company )
<%= form.collection_select(:contact_id, @contacts, :id, :name_and_company ) %>
Categorized as Ruby On Rails
This doesn’t work.
View:
Controller:
def custom_name
@custom_name = ‘test’
end
Error:
undefined method `custom_name’ for #
It works nevertheless.
I confused Model with Controller.
Sorry for the noise…
Sorry for the delay in my response Michael. Cool to see this post has helped you.
where do you write
‘
‘
form.collection_select(:contact_id, @contacts, :id, :name_and_company )