1

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

唯一不起作用的解决方案是使用 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"
4

1 回答 1

0

看起来您缺少关闭)您的 select_tag 行,您可以通过向您添加另一个参数来添加选定的值options_for_select

select_tag(:age_from, options_for_select(18..60, params[:age_from]))
于 2012-10-07T23:22:46.860 回答