How to make the f.select rails selected

与世无争的帅哥 提交于 2019-12-03 04:59:47

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

You should pass :selected option to options_for_select method, like this:

<%= f.select :area, options_for_select([['a','a'],['b','b'],['c','c']], :selected => params[:area]), {}, { :class => 'span3 controls controls-row' } %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!