Rails: Restoring contents of non-model form that uses form_tag

旧城冷巷雨未停 提交于 2019-12-01 18:13:36

The second arg to text_field_tag is the value to fill in the field with. Try something like this:

  <%= text_field_tag "separator", params[:separator], :maxlength => 1 %>

If your field has a default, you will want to set it from the "show" action for the form:

# GET
def show_form
  params[:key] = 'default'
end

# POST
def validate_form_and_act
  # Don't set it here to reuse what the user passed.
end

or directly on the template (less good because uses an || every time and adds more controller data to view):

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