Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

options_for_select selected value not working

I have a form for projectuser data, but when I edit the projectuser, the selected projectuser stays empty, what is going wrong? This is the code:

= f.select :user_id, options_for_select(@users.map{ |u| [u.full_name, u.id] }, selected: @projectuser.full_name), include_blank: true
like image 906
John Avatar asked Dec 04 '13 11:12

John


1 Answers

The documentation states:

(...) 
options_for_select(container, selected = nil) public
(...)
(million examples)

So you shouldn't pass selected: something, but just something. Also, this something needs to be selected value, not text:

= f.select :user_id, options_for_select(@users.pluck(:name, :id), @projectuser.id), include_blank: true
like image 143
BroiSatse Avatar answered Sep 23 '22 08:09

BroiSatse