016. form 表单中下拉选项改变,表单自动提交 onchange & javascript_tag - cwy007/tips-and-skills GitHub Wiki
<%= form_tag store_index_path, method: :get, class: "locale" do %>
<%= select_tag 'set_locale',
options_for_select(LANGUAGES, I18n.locale.to_s),
onchange: 'this.form.submit()' %>
<!-- 当浏览器没有打开js时,会显示这个送出按钮 -->
<%= submit_tag 'submit' %>
<!-- 隐藏这个送出按钮 -->
<%= javascript_tag "$('.locale input').hide()" %>
<% en
source:agile web development with rails ---book