Open ghost opened 8 years ago
I'm removing the default scope from the whole app to see if this helps. After thinking more about it, I don't really need this to be a multi-tenant app since only one user is adding books in the backend.
Update: Still doesn't work. :(
After changing to this format : http://www.lauradhamilton.com/how-to-filter-by-multiple-options-filterrific-rails
Which does give all the needed elements for the side filters , I've abandoned trying to get this to work with the checkboxes. I'll have to come up with something else.
After making the change only one set of checkboxes would work (the first set). Upon putting things back like they were above, still only the first set of checkboxes would work and nothing else.
I removed the filterrific interaction with the checkboxes and left only the search and sort filter and now those are working.
I'm having a similar issue. Everything works well except the :with_type
checkboxes. Am I missing anything?
Model
filterrific(
default_filter_params: { sorted_by: 'name_asc' },
available_filters: [
:sorted_by,
:search_query,
:with_type
]
)
scope :with_type, lambda { |card_types|
where(type: [*card_types])
}
Application Controller
def initialize_filterrific_for_cards
initialize_filterrific(
Card,
params[:filterrific],
select_options: {
sorted_by: Card.options_for_sorted_by
},
persistence_id: true,
default_filter_params: { sorted_by: 'name_asc' }
)
end
DecksController - decks#build
def build
@filterrific = initialize_filterrific_for_cards or return
@cards = @filterrific.find.page(params[:page])
respond_to do |format|
format.html
format.js
end
rescue ActiveRecord::RecordNotFound => e
puts "Had to reset filterrific params: #{ e.message }"
redirect_to(reset_filterrific_url(format: :html)) and return
end
View
<%= form_for_filterrific @filterrific do |f| %>
<ul class="card_types_filter">
<li>
<%= f.check_box :with_type, {multiple: true}, "Monster", false %>
<%= f.label :with_type, value: "Monster", class: "monster_label noselect" do %>
<%= image_tag "card_icons/normal_card_icon.png" %>
Monsters
<% end %>
</li>
<li>
<%= f.check_box :with_type, {multiple: true}, "Spell", false %>
<%= f.label :with_type, value: "Spell", class: "spell_label noselect" do %>
<%= image_tag "card_icons/spell_card_icon.png" %>
Spells
<% end %>
</li>
<li>
<%= f.check_box :with_type, {multiple: true}, "Trap", false %>
<%= f.label :with_type, value: "Trap", class: "trap_label noselect" do %>
<%= image_tag "card_icons/trap_card_icon.png" %>
Traps
<% end %>
</li>
</ul>
<% end %>
Solved my issue. Used the latest github version to allow multiple inputs. {multiple: true}
was breaking it.
gem 'filterrific', git: 'https://github.com/ayaman/filterrific.git'
i have tried this new GitHub version the multiple issue us solved but now my single input filter not working? have you tried this ?
What do you mean by single input filter? A single checkbox? I'll help you out if show me the code or the error you're getting in the logs.
All the above methods do not work.
scope
only works if a string is passed in the URL, but not an array.
For example, if you send something similar to this in the parameters:
with_categories_ids:
- '24'
- '33'
- '45'
The eponymous scope
in the Post model does not work. But if you change the passed parameter to a string:
with_categories_ids: '33'
Then all at once will work.
It is impossible for Rails to work normally with Filterrific. I do not understand why the author (@jhund) of Filterrific is so irresponsible about this issue.
I have a list of books. There are filters on top of the list for search and your standard sort dropdown. Then on the side are checkbox filters (see image below).
I setup the Filterrific gem according to the documentation, only for the top search and sort filters at first. They worked great on the "All Books" list page, "Series" book list page and the "Collections" book list page. These are all managed by their own controllers but all use the "title" model. A few days after getting the top filters to work, I got the side filters to work using Filterrific. I only did the side filters on the "All Books" list page for now. I wanted to get everything working on that one first before moving it to the other pages.
So the side filters work perfectly but now the search and sort filters no longer work as expected. If I change the sort order nothing happens. Let's say I change it to list the titles from Z to A. The list doesn't change. If I tick one of the side filters then the list changes according to the side filter. BUT if I untick the side filter then the list changes according to the sort dropdown option I'd chosen prior to ticking the side filter. Changing the sort filter again does nothing. It's only working after I tick and untick a side filter. The search filter doesn't work at all anymore.
My "Title" model:
My "Books" Controller:
My "Books Index" view:
My "index.js":
My "list" partial:
I was under the impression all of these different filters should work under one filterrific form. I have tried separating them but that didn't work either because I wasn't really sure how to have two separately working filterrific forms. I've tried putting the filters in the same order in the model as they are in the view. I've moved the filterrific_results div in and out of the partial. Still I have this strange behavior. It seems like with the way this is setup, all of the filters should be working accurately. I'm not sure what else to try.
I'm using: filterrific (2.0.5) rails (4.2.3) ruby-2.0.0-p643
Sorry, I posted this on Stackoverflow and there is no response and this is the only thing delaying this site launch. I figure if I post here too maybe other github users can help .