[英]ActiveAdmin issue with Scoped Resource
我在資源頁面上具有以下范圍:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.