Question

I have a table named events in ActiveAdmin.

There is a field called eventdate and in here there is a date of the event.

I am looking to be able to have an action that when the current date is over the event date the table gets an automatic selection in a selectbox called 'event ended'. This basically says the event is expired.

Is this possible or is there a gem that does this already for ActiveAdmin?

Sorry its such a basic question but this is all I have got.

Cheers

Était-ce utile?

La solution

I would define define two things on your Event model: expired scope, and expired? method:

class Event < AR::Base
  scope :expired, -> { where('eventdate < ?', Date.today) }

  def expired?
    eventdate < Date.today
  end
end

To list all expired events you can simply call:

Event.expired

If you are listing all the events and want to add some custom logic for expired one, you can wrap this logic in if event.expired?.

You probably also should inverse scope as well:

scope :not_expired, -> { where.not('eventdate < ?', Date,today) }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top