Ruby-on-rails 如何为 Rails SimpleForm 选择框设置默认选定值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10441061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 03:20:59 来源:igfitidea点击:
How to set default selected value for Rails SimpleForm select box
提问by Eric Muyser
I'm trying to figure out how to set the selected option of a select box generated by SimpleForm. My code is along the lines of:
我试图弄清楚如何设置SimpleForm生成的选择框的选定选项。我的代码是这样的:
<%= simple_form_for(@user) do |f| %>
<%= f.association :store, default: 1 %>
Of course the default: 1part does not work.
当然,这default: 1部分不起作用。
TIA
TIA
回答by 0x4a50
Use the following:
使用以下内容:
selected: 1
回答by Abram
You can now use the following:
您现在可以使用以下内容:
<%= f.association :store, selected: 1 %>

