How to set default selected value for Rails SimpleForm select box

我只是一个虾纸丫 提交于 2019-12-18 03:49:01

问题


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:

<%= simple_form_for(@user) do |f| %>
  <%= f.association :store, default: 1 %>

Of course the default: 1 part does not work.

TIA


回答1:


Use the following:

selected: 1



回答2:


You can now use the following:

<%= f.association :store, selected: 1 %>


来源:https://stackoverflow.com/questions/10441061/how-to-set-default-selected-value-for-rails-simpleform-select-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!