2016-06-13 36 views
0

我有一個資源頁面上的以下內容:ActiveAdmin問題與作用域資源

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

回答

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