How do i use scopes in Active Admin, In this example I am trying to display all members who's expiry date is equal to today's date.
class Member < ActiveRecord::Base
--- Code removed for brevity
#Scopes
scope :expired_today, where(:expiry_date == Date.today)
end
Within the active admin dashboard i then want to display all those members who have expired
columns do
column do
panel "Expired Memberships", :class => 'expiredmemberships' do
table_for Member.expired_today do
column("Name") do |m|
"#{m.forename} #{m.surname}"
end
end
end
end
end
This is not working though, could someone give me a helping hand with an explanation on what needs to be done please
where
works with scopes the same way it works everywhere else in Rails:You give it a hash with a key/value. Your way, using
==
, basically invokeswhere(false)
, as the==
isn't "passed in", it's resolved instantly (to false as a symbol and date will always be unequal) and the resulting value is passed towhere
.