如何在提交后重新填充rails form_for的表单字段?

时间:2012-10-07 22:55:52

标签: ruby-on-rails ruby-on-rails-3 form-for repopulation

我有这个表单并尝试了很多aproches,无法在提交后重新填充rails form_for的表单字段。这是正确的方法吗?也许只是忽略了文档,但没有很好的参考如何:(

唯一不可行的解决方案是使用params标记并将集合的默认值设置为,但如果表单未提交,则此操作也会失败。 PARAMS [:AGE_FROM]

= form_for:people,:url => request.fullpath,:method => :get,:html => {:class => 'form-search'} do | f |

  #container_search
    .clear
      = select_tag(:age_from, options_for_select(18..60)
      = select_tag(:age_to, options_for_select(18..60)
      = select_tag(:gender, options_for_select(gender)
    .clear
    .center
      = f.submit "Search »", :class => "span-4"

1 个答案:

答案 0 :(得分:0)

您的select_tag行似乎没有关闭),您可以通过向options_for_select添加另一个参数来添加所选值:

select_tag(:age_from, options_for_select(18..60, params[:age_from]))