中的以下类方法ActiveAdmin.rb
将根据条件返回所有记录,例如ActiveAdmin.current("Yes")
或ActiveAdmin.current("No")
。
def self.current(inp = "Yes") # default inp is "Yes"
d = Time.zone.now.to_date
return case inp
# when inp == "Yes" it would return all the records with archived == false (won't return archived == nil)
# AND parents with start_date <= d and end_date >= d
when "Yes"
where(archived: false ).
joins(:parent).
where("parents.start_date <= ? AND parents.end_date >= ?",d,d)
# when inp == "No" it would return all the records with archived == true (won't return archived == nil)
# AND parents with start_date > d OR end_date < d
when "No"
where(archived: true ).
joins(:parent).
where("parents.start_date > ? OR parents.end_date < ?",d,d)
# when inp = "Any" return all records
when "Any"
scoped
# return all records if inp does not match any of the above options
else
scoped
end
end