Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails NoMethodError(未定义的方法`锁定';_Ruby On Rails_Ruby_Activerecord_Ruby On Rails 3.2_Locking - Fatal编程技术网

Ruby on rails NoMethodError(未定义的方法`锁定';

Ruby on rails NoMethodError(未定义的方法`锁定';,ruby-on-rails,ruby,activerecord,ruby-on-rails-3.2,locking,Ruby On Rails,Ruby,Activerecord,Ruby On Rails 3.2,Locking,我在生产环境中的应用程序中以随机速率出现错误。当我重新启动服务器时,问题消失了一段时间,然后重新出现 这就是错误所在 NoMethodError (undefined method `locked' for #<Class:0x00000006776a40>): app/controllers/orders_controller.rb:29:in `rescue in new' app/controllers/orders_controller.rb:29:in `new'

我在生产环境中的应用程序中以随机速率出现错误。当我重新启动服务器时,问题消失了一段时间,然后重新出现

这就是错误所在

NoMethodError (undefined method `locked' for #<Class:0x00000006776a40>):
  app/controllers/orders_controller.rb:29:in `rescue in new'
  app/controllers/orders_controller.rb:29:in `new'
用于解释。此剪接预先选择前端中的产品选项

错误发生在其他领域,也与
ProductOption
模型有关

型号
产品\u选项
如下所示:

@order.product_option = ProductOption.find_by_identifier(params[:product]) rescue ProductOption.first
class ProductOption < ActiveRecord::Base
  attr_accessible :identifier, :price, :servings, :title

  before_destroy :check_for_deps

  has_many :users
  has_many :orders
  belongs_to :product

  attr_accessible :product_id, :product, :price, :identifier, :servings, :color

  validates_presence_of :identifier, :price, :product
  validates_numericality_of :price, greater_than_or_equal_to: 1
  validates_numericality_of :servings, greater_than_or_equal_to: 1

  default_scope order('products.position, servings').includes(:product)

  def title
    I18n.t 'order_form.product_option_title',
           recipe_count: self.product.recipe_count,
           product_title: self.product.title,
           servings: self.servings
  end

  def subtitle
    self.product.subtitle
  end

  def pretty_price
    '%.2f' % self.price
  end

  def check_for_deps
    if users.count > 0
      errors.add(:base, I18n.t('model.validation.product_has_still_objects_assigned'))
      return false
    end

    if orders.count > 0
      errors.add(:base, I18n.t('model.validation.product_has_still_objects_assigned'))
      return false
    end
  end

end
我使用的是Rails v3.2.18

故障排除 当我做一些研究时,我偶然发现了这个rails问题。但是这个问题已经结束,并被宣布为不是一个bug

根据@lifius,我运行了以下命令:

culprit = :locked
ActiveRecord::Base.descendants.find {|e| e.singleton_methods.include?(culprit)}

# Result
Delivery(id: integer, delivery_date: date, remarks: text, created_at: datetime, updated_at: datetime, status: string)

您可以执行以下操作:

Rails.application.eager_load!
ActiveRecord::Base.descendants.find {|e| e.singleton_methods.include?(:locked)}

在rails控制台中,查看受影响的模型。

您能否向我们提供
ActiveRecord::Base.subjections.find{e | e.singleton_方法的输出。include(:locked)}
(请确保首先调用
rails.application.eager_load!
)?似乎有些型号包含
范围:locked
self.locked
@lifus我确实有一个
范围
名为
locked
。我将删除此项,我想这将解决问题。您可以将此作为答案发布,我很乐意接受。
Rails.application.eager_load!
ActiveRecord::Base.descendants.find {|e| e.singleton_methods.include?(:locked)}