0

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

Richlewis
  • 15,070
  • 37
  • 122
  • 283

1 Answers1

1

where works with scopes the same way it works everywhere else in Rails:

where(:expiry_date => Date.today)

You give it a hash with a key/value. Your way, using ==, basically invokes where(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 to where.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • you know what i just realised, so silly of me, ill credit the answer to you though, thanks for explaining – Richlewis Dec 12 '13 at 13:45