jhund / filterrific

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
http://filterrific.clearcove.ca
MIT License
910 stars 124 forks source link

How to pass user ID into the model? #163

Closed jhlatz closed 6 years ago

jhlatz commented 6 years ago

I'm trying to only show items that a user has favorited but for some reason every time the query is executed it's the same user ID if a checkbox is checked. This is the scope I'm using scope :favorites, lambda { |user| return nil if 0 == user where("promos.id IN (SELECT votes.votable_id FROM votes WHERE votes.voter_id = ?)", user) }

The controller def index @filterrific = initialize_filterrific( Promo, params[:filterrific], select_options: { sorted_by: Promo.options_for_sorted_by, with_promo_type: Promo.options_for_promo_type }, persistence_id: 'shared_key', default_filter_params: {} ) or return @promos = @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

And the view <span class="filter_sort"> Favorites <%= f.check_box(:favorites, value: current_account.id)%> </span>