gr0k
gr0k

Reputation: 829

Showing multiple attributes for Rails drop down menu

I'm working my edit view and trying to implement a drop down box which shows multiple attributes from a model. I have an equipment model which includes an item description and an item serial number. Is there a way to implement this so that the drop down menu shows Item Description - Serial Number?

I was thinking about using a method to combine the 2 attributes into a single virtual attribute and display it, but I was wondering if there was an easier way to do this first.

Upvotes: 1

Views: 969

Answers (1)

Anton Grigoryev
Anton Grigoryev

Reputation: 1219

select_tag :equipment, options_for_select(Equipment.all.collect {|e| ["#{e.description} - #{e.serial}", e.id] }), :include_blank => true

Upvotes: 1

Related Questions