I'm trying to set the default value of my form field, but I'm not sure where I can pass in that information. Here's what I have so far:
我试图设置表单字段的默认值,但我不确定可以在哪里传递这些信息。这是我目前所拥有的:
def month_options
[["JAN", "01"], ["FEB", "02"], ["MAR", "03"], ["APR", "04"], ["MAY", "05"], ["JUN", "06"], ["JUL", "07"], ["AUG", "08"], ["SEP", "09"], ["OCT", "10"], ["NOV", "11"], ["DEC", "12"]]
end
In my view, I'm using this:
在我看来,我用的是:
<%= select_tag :month, options_for_select(month_options, params[:month]) %>
I'd like to be able to set the default value of my form field to the current month.
我希望能够将表单字段的默认值设置为当前月份。
2 个解决方案
#1
2
Perhaps
也许
<%= select_tag :month, options_for_select(month_options, params[:month] || "JAN") %>
...if you want the selected value to default to "Jan" of params[:month]
is nil
.
…如果您希望选择的值默认为参数[:month]的“Jan”,则为nil。
#2
0
Pass the selected option like this:
通过选择的选项如下:
:selected => params[:default_value]
You can pass a parameter, string, etc whatever your case may be.
您可以传递参数、字符串等等。
#1
2
Perhaps
也许
<%= select_tag :month, options_for_select(month_options, params[:month] || "JAN") %>
...if you want the selected value to default to "Jan" of params[:month]
is nil
.
…如果您希望选择的值默认为参数[:month]的“Jan”,则为nil。
#2
0
Pass the selected option like this:
通过选择的选项如下:
:selected => params[:default_value]
You can pass a parameter, string, etc whatever your case may be.
您可以传递参数、字符串等等。