【问题标题】:ActiveAdmin issue with Scoped Resource范围资源的 ActiveAdmin 问题
【发布时间】:2016-06-13 19:27:38
【问题描述】:

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

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

【问题讨论】:

    标签: ruby-on-rails activeadmin


    【解决方案1】:
    def self.current_active_event_registrations
      events = self.not_expired_active
      if events.blank?
        all
      else
        events.first.registrations
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-18
      • 2013-10-16
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多