How to make the f.select rails selected

后端 未结 4 1964
春和景丽
春和景丽 2021-02-07 02:32

It\'s my code:

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


        
4条回答
  •  渐次进展
    2021-02-07 03:07

    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 ; )

提交回复
热议问题