tag rails form_for form collection_select collection ruby-on-rails select option selected

ruby-on-rails - form_for - select box rails 5



Cómo hacer que los carriles f.select seleccionados (2)

Es mi código:

<%= f.select :area, options_for_select([[''a'',''a''],[''b'',''b''],[''c'',''c'']]), {}, {:class => ''span3 controls controls-row''}, :selected => params[:area] %>

y el resultado es:

ArgumentError in Users#edit Showing /home/airson/rails_projects/friends_of_local/app/views/users/edit.html.erb where line #17 raised: wrong number of arguments (5 for 4)

por qué.....@@?


Debería pasar :selected opción :selected al método options_for_select , así:

<%= f.select :area, options_for_select([[''a'',''a''],[''b'',''b''],[''c'',''c'']], :selected => params[:area]), {}, { :class => ''span3 controls controls-row'' } %>


No es necesario utilizar :selected simplemente pase sus params[:area] solo a options_for_select como segundo argumento:

<%= f.select :area, options_for_select([[''a'',''a''],[''b'',''b''],[''c'',''c'']], params[:area]), {}, { :class => ''span3 controls controls-row'' } %>

Se seleccionará el último valor de tus params[:area] .

Espero eso ayude ; )