Show name and id both in select tag haml ruby and rails

Viewed 194

I am working on ruby on rails project and I need to show the id and name of option in dropdown. I tried with the following code but its showing on the name of the field.

select_tag "select", options_for_select(@subject.map{ |u| [u.altername, u.id] }), :multiple => true

English(457865) Math(7895452)

Like this, I want to show

1 Answers

Try following, with select

f.select "select", @subject.map{ |u| ["#{u.altername}(#{u.id})", u.id] }, :multiple => true

with select_tag

select_tag "select", options_for_select(@subject.map{ |u| ["#{u.altername}(#{u.id})", u.id] }), :multiple => true
Related