简体   繁体   中英

how to persist search term in the field

i am using ruby on rails and have a search form like:

 <%= form_tag '/findBlood' do %>
        Blood Group   <%= text_field_tag "bloodGroup" %>
        <%= submit_tag "Search", class: "btn btn-large btn-primary"%>
    <% end %>

This works as expected however, on submit the bloodGroup field clears and as a result probably pagination breaks. how to retain this field?

This should do the trick for you

<%= text_field_tag 'bloodGroup', params[:bloodGroup] %>

See docs for text_field_tag


The reason a symbol works and the string (other answer) doesn't work:

foo = {hello: 'world'}
puts foo[:hello];        # => 'world'
puts foo['hello']        # => nil
puts foo['hello'.to_sym] # => 'world'

You can easily convert between strings and symbols in Ruby, but they are not equal.

试试这个

<%= text_field_tag "bloodGroup", params["bloodGroup"] %>

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