Rails模型范围在控制台中返回未定义的方法

时间:2019-10-31 13:42:41

标签: ruby-on-rails rails-console

我为我的课程定义了一个命名范围:

class Contract < ApplicationRecord
  include AASM

  scope :is_effective_at, ->(date) { where('? BETWEEN starts_at AND expires_at', date) }

end

在Rails控制台中,当我尝试访问示波器时:

irb(main):002:0> Contract.is_effective_at(Date.current)
Traceback (most recent call last):
        2: from (irb):2
        1: from (irb):2:in `rescue in irb_binding'
NoMethodError (undefined method `is_effective_at' for Contract (call 'Contract.connection' to establish a connection):Class)

当我用reload!重新加载控制台时,它可以工作,但是其他类中的所有其他作用域都可以正常工作。 我不明白为什么该类不加载任何作用域,这个类与另一个类的唯一区别是该类具有120 LOC。

有任何想法吗?

0 个答案:

没有答案
相关问题