【问题标题】:Rails 4.1.0 undefined method `call' for after upgrading from rails 4.0.0 [duplicate]从rails 4.0.0升级后的Rails 4.1.0未定义方法“调用” [重复]
【发布时间】:2015-05-02 07:43:47
【问题描述】:

您好,我已从 rails 4.0.0 升级到 Rails 4.1.0

现在我得到了这个错误:

当我删除时

.active

它有效...但是为什么呢?我该如何解决这个问题?

课程.rb

  self.inheritance_column = :_type_disabled
  has_and_belongs_to_many :clients, :join_table => :clients_courses  # TODO c
  has_many :memberships, :dependent => :destroy
  has_many :users, :through => :memberships

  has_many :lessons,
        -> {order "lessons.sort ASC, lessons.start_date"},
        :dependent => :destroy,
        :foreign_key => :course_object_id

  scope :active, where(:active => true)
  scope :inactive, where(:active => false)

【问题讨论】:

  • 那你有方法active吗?
  • 请告诉我们app/models/course.rb
  • 我在上面添加了 course.rb。

标签: ruby-on-rails ruby ruby-on-rails-4 activerecord ruby-on-rails-4.1


【解决方案1】:

Change you course.rb code to:

  scope :active, -> { where(:active => true) }
  scope :inactive, -> { where(:active => false) }

【讨论】:

    【解决方案2】:

    You should provide lambda to the scope 在你的course.rb:

    scope :active, -> { where active: true }
    scope :inactive, -> { where active: false }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      相关资源
      最近更新 更多