Search code examples
ruby-on-railsselectselected

How to make the f.select rails selected


My code:

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

The result is:

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)

Why am I getting this error?


Solution

  • No need to use :selected just pass your params[:area] alone to options_for_select as a second argument:

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

    The last value of your params[:area] will be selected.

    Hope it helps ; )