I have several scoped methods. When I call them in the console, I get the expected results. When I view them, the scopes are not applied. I see "all", regardless of the filtered scope method. Any ideas?
EDIT - I'm using Ransack to filter results, hence the @search
.
Also, do you guys know a cleaner way to compare a datetime to 1.year.ago? What I have below works in the console, but I'm sure there's a nicer way to compare.
Thanks in advance.
invoice.rb
def self.open
where(closed: false)
end
def self.this_year
current_year = 1.year.ago
where("invoice_date >= ?", current_year)
end
invoices_controller:
def index
@search = Invoice.this_year.open.search(params[:q])
@invoices = @search.result.paginate(:page => params[:page], :per_page => 25)
@count = @invoices.count
render 'shared/invoices.html.erb'
end