Ransack, acts-as-taggable-on and checkboxes in search form

need some help on ransack filtering.

I have model Project, which has many tags through acts_as_taggable gem.

class Project < ActiveRecord::Base
  include PublicActivity::Common

  belongs_to :customer
  belongs_to :category
  has_many :attachments, :as => :attachable
  has_many :reports, :dependent => :destroy
  has_many :messages, :dependent => :destroy
  has_many :screens, :dependent => :destroy

  accepts_nested_attributes_for :attachments, :allow_destroy => true


so the @project.tags - works in console just fine.

However, I have advanced search form with ransack gem on index page, and
need to filter projects depending on tags which are selected by user. So
that only projects which have all of the selected tags were displayed.

Also a have categories, projects belong to categories. So the checkboxes
for categories work as expected. But how can i do checkboxes for tags?
Here’s my form for search:

= search_form_for @search do |f|
  - @categories.each do |category|
    = check_box_tag('q[category_id_eq_any][]', category.id)
      = category.name
  = f.text_field :budjet_gteq
  = f.text_field :budjet_lteq
  - @tags.each do |tag|
    = check_box_tag('q[tags_id_eq_all][]', tag.id)
    = tag.name

That’s what i have in console after submiting the form (so i have no
query at all, even though i checked two checkboxes):

Processing by ProjectsController#index as HTML
  Parameters: {"utf8"=>"✓", "q"=>{"category_id_eq_any"=>["1"],

“budjet_gteq”=>“100000”, “budjet_lteq”=>“70000000”}}

Any help will be appreciated.

Edited my view, so now checkboxes for tags look like:

  • @tags.each do |tag|
    = check_box_tag(“q[tags_id_eq_all][]”, tag.id, {})
    = tag.name

So in console i can see such query:

Processing by ProjectsController#index as HTML
Parameters: {“utf8”=>“✓”, “q”=>{“budjet_gteq”=>"", “budjet_lteq”=>"",
“tags_id_eq_all”=>[“1”, “2”, “3”, “4”, “5”, “6”]}}

So now, it passes all tags, even though i’ve selected only two of them.
the result it shows all projects, when i want to show only one, with two
tags which i’ve checked.

Sorry guys, problem was not in Ransack or checkboxes. it’s all about
and styles, as checkboxes simply didn’t get checked when i clicked them.
Fixing styles helped

Now i’ve played a bit and see that when in view i have:

  • @tags.each do |tag|
    = check_box_tag(“q[tags_id_eq_all][]”, tag.id, {})
    = tag.name

every checkbox in html is set to “checked” by default.
If i make it false, like this:

  • @tags.each do |tag|
    = check_box_tag(“q[tags_id_eq_all][]”, tag.id, false, {})
    = tag.name

Checkboxes are nit checked by default, but it doesn’t send query with
tags_ids array at all, even if i click on them.
Can’t figure out, how can i get it working…