作用域内资源的活动管理员问题



我在资源页面上有以下范围:

scope("Current Active Event Registrations") { |scope| Event.current_active_event_registrations }

我在查看页面时不断遇到的错误是:

undefined method `except' for nil:NilClass
 c = c.except :select, :order

Event中的代码如下所示:

class Event < ActiveRecord::Base
  has_many :registrations
  scope :active_event, -> { where(active: true) }
  scope :not_expired_active, -> { active_event.where('end_at > ?', DateTime.now) }
  after_save :check_for_other_active_events
  def random_winner
    self.registrations.order("RANDOM()").first
  end
  def self.current_active_event_registrations
    events = self.not_expired_active
    events.first.registrations unless events.blank?
    all if events.blank?
  end
  private
    def check_for_other_active_events
      Event.where('id != ?', self.id).update_all(active: false) if self.active
    end
end

我只是想将自定义范围添加到我的 ActiveAdmin 后端中的注册资源页面。

我正在使用Rails 4和最新的ActiveAdmin

def self.current_active_event_registrations
  events = self.not_expired_active
  if events.blank?
    all
  else
    events.first.registrations
  end
end

最新更新