Question

I'm using the gem ransack in a Rails app. It is a very useful gem!

But, after the search takes place, the text fields keep what you typed in and the select drop-downs don't.

This is an example text search (it stays in place after you search):

<div class="field" >
  <p><%= f.label :description_cont, "Description:" %></p>
  <p><%= f.text_field :description_cont %></p>
</div>

This is an example of a related field that uses a select drop-down (and what you select gets cleared after you search):

<div class="field" >
  <p"><%= f.label :client_client_name_cont, "Client:" %></p>
  <p><%= f.select :client_id_eq, options_from_collection_for_select(Client.all, "id", "client_name"), include_blank: true %></p>
</div>

How can I keep the dropdown selected value after the search?

Thanks for your help!

Was it helpful?

Solution

This worked:

    <td><%= f.collection_select(:client_id_eq, Client.all, :id, :client_name) %></td>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top