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

It is possible that filterrific to cancel my @jobs = Job.jobs_by(current_user) #170

Open ovi-tsb opened 5 years ago

ovi-tsb commented 5 years ago

I have in my jobs_controller def index @jobs = Job.jobs_by(current_user)

and in job.rb model scope :jobs_by, ->(user) { where(user_id: user.id) }

This should let users to see only jobs what they created, but now it show me jobs from all users. Do you think is something in filterrific what can cancel Job.jobs_by(current_user) ?

cartond commented 5 years ago

What is the rest of your controller code?

What I did, is in the controller define a default scope. So for example in the Filterrific demo, Student with a default scope of for example freshman (making it up):

def index
    (@filterrific = initialize_filterrific(
      Student.freshman,
      params[:filterrific],
      select_options: {
        sorted_by: Student.options_for_sorted_by,
        with_country_id: Country.options_for_select,
      },
    )) || return
    @students = @filterrific.find.page(params[:page])

    respond_to do |format|
      format.html
      format.js
    end
  end

Hopefully, this is the correct approach...?