Sasha Chilly
2013-May-27 06:27 UTC
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.
Project.rb:
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
acts_as_taggable
end
so the @project.tags - works in console just fine.
However, I have advanced search form with ransack gem on index page, and i
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
tags
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.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/57072c69-9972-4415-b3d3-021b603ca2dc%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Sasha Chilly
2013-May-27 09:58 UTC
Re: Ransack, acts-as-taggable-on and checkboxes in search form
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.
As
the result it shows all projects, when i want to show only one, with two
tags which i''ve checked.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/64f653db-bcda-413a-b255-616001f4c3df%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Sasha Chilly
2013-May-30 08:35 UTC
Re: Ransack, acts-as-taggable-on and checkboxes in search form
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..
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/8c785914-87c1-49ff-9402-0bc438a0db24%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Sasha Chilly
2013-May-30 10:01 UTC
Re: Ransack, acts-as-taggable-on and checkboxes in search form
Sorry guys, problem was not in Ransack or checkboxes. it''s all about html and styles, as checkboxes simply didn''t get checked when i clicked them. Fixing styles helped -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/58482798-1945-40ba-b435-2c906bcd400c%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.