2
votes

I am trying to add a hidden field in a ransack form which is not to be evaluated by the ransack search method and I want to evaluate it manually in the controller. How would I go about doing that?

In my case below I want to pass the controller a city id and evaluate it without ransack doing anything with it.

= search_form_for @q do |f|
      = f.label "Has Mobile"
      = f.check_box :mobile_true
      = f.hidden_field :city_id, :value =>@city.id

How would I go about this?

2

2 Answers

4
votes

You can add ransack predicate after field name. :city_id_eq

= search_form_for @q do |f|
  = f.label "Has Mobile"
  = f.check_box :mobile_true
  = f.hidden_field :city_id_eq, :value =>@city.id

Predicates https://github.com/ernie/ransack/wiki/Basic-Searching

1
votes

The problem is that you are using the form helper when you define the hidden field. The form helper includes the hidden field in the search parameters. So, just use the standard Rails helper instead.

Replace

f.hidden_field :city_id, :value =>@city.id

with

hidden_field_tag :city_id, @city.id