简体   繁体   English

Ruby on Rails:提交搜索表单后保持用户输入

[英]Ruby on Rails: Keep user input after submitting search form

Quick question. 快问。 When submitting a search, some of my fields save the user input in the text field or drop down menu after the search has been done, but for other fields, it reverts back to the default choice. 提交搜索时,我的一些字段会在搜索完成后在文本字段或下拉菜单中保存用户输入,但对于其他字段,它将恢复为默认选项。 How do I make them save the users choice. 如何让他们保存用户选择。

    Start date:
<%= select_tag "start_date_dd", options_for_select({
    "Select a period" => "",
      "3 days ago"   => DateTime.now.to_date - 3.days,   # =    259_200 sec.
      "1 week ago"   => DateTime.now.to_date - 1.week,   # =    604_800 sec.
      "1 month ago"  => DateTime.now.to_date - 1.month,  # =  2_592_000 sec.
      "6 months ago" => DateTime.now.to_date - 6.months, # = 15_552_000 sec.
      "1 year ago"   => DateTime.now.to_date - 1.year,   # = 31_557_600 sec.
    }, :selected=>params[:start_date_dd] )%></br>



Status :

<%= select(@projects, :status, Project.all.map {|p| [p.status]}.uniq, :prompt => "-Any-", :selected => params[:status]) %></br>

Here my status dropdown box keeps the user input in the text box, but my start date drop down menu does not. 在这里,我的状态下拉框将用户输入保留在文本框中,但我的开始日期下拉菜单没有。 Any way around this. 任何解决方法。 Thanks 谢谢

:selected => params [:status]是你的状态下拉框保留你需要添加的值的原因:selected => params [:start_date_dd]添加到标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM