rails select_tag selected value

后端 未结 4 1706
孤街浪徒
孤街浪徒 2020-12-23 19:24

For the code given below I wanted to keep the select box selected with the value that is passed.

But this doesn’t work:

@yrs =[2011,2010,2009,2008]
&         


        
4条回答
  •  失恋的感觉
    2020-12-23 19:34

    Remove the :selected=> part.

    Syntax:

    options_for_select(@options, @selected_options)
    

    Usage:

    options_for_select(1..5, 3)  # creates a range 1..5 , with 3 as selected by default
    

提交回复
热议问题