I have a model with some scopes defined on it:
class Alarm < ActiveRecord::Base
scope :open_alarms, where("state != ?", AlarmStates::STATELIST[-1])
scope :new_alarms, where('state is null')
scope :site_alarms, lambda{ |site| where(:mac_address => site.mac_address)}
#etc
end
These scopes are all Relation objects, so I should be able to chain them in a with_scope call. But I can’t get it all to work. I have been trying something along the lines of
Alarm.with_scope(:find => Alarm.open_alarms){all}
which, AFAIK, should apply the Relation Alarm .open_alarms onto the find, and then effectively find all alarms matching the open_alarms scope. But I get an ‘unidentifed variable or method “all” for Main:Object’ error when I try this. I have tried a whole series of variants, but nothing seems to get there.
Where I am trying to get to is being able to chain a series of scopes, then apply pagination so I can output pages of alarms.
Any help would be very much appreciated.
Thanks,
Steve
@alarms = Alarm.open_alarms.page(params[:page])
@alarms = Alarm.open_alarms.site_alarms(“http://sample.me”).page(params[:page])
(Using gem will_paginate or kaminari).
You seem to be using pre 3.2 code to do your query.