In my feeble attempt to write better Model methods, I am failing hard. Which in turn, has brought me to ask my question here.
Here is my Model:
class Group < ActiveRecord::Base
# Because of inheritance issues with ActiveRecord
# We tell this Relation to use a "false" column to persuade
# The relation to push forward without worrying about Inheritance
self.inheritance_column = :_type_disabled
scope :expired?, where('expiration_date > ?', Time.now)
end
This is what I am trying to do with my scope
g = Group.find(91)
g.expired?
So, essentially see if I can tell if the group is expired. Now, I know I can write this in my controller in my activerecord where statement, but I am trying to better understand handling data in models with Rails
That’s not what scopes are for 😉
To do what you want, just add an instance method:
An
expiredscope would be use to select expired groups:And you would use it like that: