Rails select helper - Default selected value, how?

后端 未结 15 1729
臣服心动
臣服心动 2020-11-29 16:06

Here is a piece of code I\'m using now:

<%= f.select :project_id, @project_select %>

How to modify it to make its default value equal

15条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 16:41

    If try to print the f object, then you will see that there is f.object that can be probed for getting the selected item (applicable for all rails version > 2.3)

    logger.warn("f #{f.object.inspect}")
    

    so, use the following script to get the proper selected option:

    :selected => f.object.your_field 
    

提交回复
热议问题