ernie/ransack — Issue #62: Problems rendering a search form from a search query
Author: ndbroadbent
Created: 2012-02-01 05:23:30+00:00
State: open

Hello,

I am building a 'saved lists' feature for our application, so that a user can save a set of filters to a 'favorites' list.

The search is working well, but I am having issues when regenerating the search form from the query string.
The problem is that Ransack does not select the correct predicate when rendering the search form, and always selects 'contains' by default.

Example:

I select `last_name` with a predicate of `blank`.

This generates the following query:

```
q[g][0][m]=and&q[g][0][c][0][a][0][name]=last_name&q[g][0][c][0][p]=blank&q[g][0][c][0][v][0][value]=true&distinct=1
```

If I then visit the index page with those query parameters in the URL, the search works fine, and returns a list of @contacts with blank last names. However, when the search form is generated, the 'contains' predicate is selected, instead of 'blank':

```html

contains

...
```

So if I click the search button now, ransack will search for `last_name contains true`, which is not very useful.

The same thing happens for all predicates, not just `blank`.

Any help would be appreciated, but I'll keep trying to figure it out.