I’m trying to use collection_select to display a drop down box from a
database table, the only problem I have is, insted of displaying :name
I’d like to display a string which is a combination of all the columns
from a specific row in a table. How should I go about this?
I’m trying to use collection_select to display a drop down box from a
database table, the only problem I have is, insted of displaying :name
I’d like to display a string which is a combination of all the columns
from a specific row in a table. How should I go about this?
That fourth parameter (where you have “:name”) just specifies a method
to call on your object. So you can put any method in there, not just a
database attribute.
In other words, you could have the following method in your mode:
def summary
“#{self.id}: #{self.name}”
end
and then pass :summary to the collection_select method, and it’ll use
the values returned by that method to populate your options tags.
I’m trying to use collection_select to display a drop down box from a
database table, the only problem I have is, insted of displaying :name
I’d like to display a string which is a combination of all the columns
from a specific row in a table. How should I go about this?
That fourth parameter (where you have “:name”) just specifies a method
to call on your object. So you can put any method in there, not just a
database attribute.
In other words, you could have the following method in your mode:
def summary
“#{self.id}: #{self.name}”
end
and then pass :summary to the collection_select method, and it’ll use
the values returned by that method to populate your options tags.
Maybe I am doing this wrong, but I can’t seem to get this to work
correctly? I defined summary my my controller file, and called :summary
from the 4th parameter of the collection_select. Am I missing
something?
I’m trying to use collection_select to display a drop down box from a
database table, the only problem I have is, insted of displaying :name
I’d like to display a string which is a combination of all the columns
from a specific row in a table. How should I go about this?
That fourth parameter (where you have “:name”) just specifies a method
to call on your object. So you can put any method in there, not just a
database attribute.
In other words, you could have the following method in your mode:
def summary
“#{self.id}: #{self.name}”
end
and then pass :summary to the collection_select method, and it’ll use
the values returned by that method to populate your options tags.