How to save a search query in the field

I use ruby ​​on rails and have a search form, for example:

 <%= 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, provided that the bloodGroup field is cleared and, as a result, pagination is possible. How to save this field?

+5
source share
2 answers

That should do the trick for you.

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

See docs for text_field_tag


The reason the character works and the string (another 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 strings and characters to Ruby, but they are not equal.

+3
source

try it

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

All Articles