Reputation: 5411
Earlier i was using This code
<%= select "selected_payment", "id", @shifts.map {|u| [' ' +u.start_time.strftime("%I:%M %p") + '-' + u.end_time.strftime("%I:%M %p")+' ',u.id]} %> to make a dropdown.
Now i have to do same thing with collection_select. But i'm not able to figure how to do it. It will be something like the one given below :
<%= f.collection_select :shift_id, @shifts,:id, :start_time, :prompt => true %>
I can not even format the date and use two values at the same time. Please help,Thanks in Advance
Upvotes: 1
Views: 1387
Reputation: 557
i found myself with the same question and i solve it doing this...
at my user.rb
def first_and_last_name
"#{self.first_name} " " #{self.last_name}"
end
at my view
<%= f.collection_select(:user_id, User.all, :id, :first_and_last_name, {}, class: 'ui search dropdown' ) %>
Upvotes: 2