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>
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>