简体   繁体   中英

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]添加到标签

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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