Ruby on Rails 3 - 回调不再起作用

时间:2011-08-16 14:53:25

标签: ruby-on-rails-3 callback


大家好。

我有一个大问题。直到2周前,我的代码工作正常,但今天我意识到一些回调不再起作用了。

回调如下:

class DetailPurchase < ActiveRecord::Base
  belongs_to :purchase, :foreign_key => 'purchase_id'
  belongs_to :product, :foreign_key => 'product_id'
  belongs_to :buy_order_detail, :foreign_key => 'buy_detail_id'

  def before_create
    Storage.create!(:product_id => self.product_id, :current_quantity => self.quantity, :stg_data => purchase.prc_data)
  end

end

这个想法是,每次创建Detail_purhase时,都应该自动创建具有相同产品的存储。

但现在它不起作用,唯一的变化是现在我使用的是jquery而不是原型

这可能是问题吗?

1 个答案:

答案 0 :(得分:2)

很奇怪它有效。正确的语法是:

class DetailPurchase < ActiveRecord::Base
  belongs_to :purchase, :foreign_key => 'purchase_id'
  belongs_to :product, :foreign_key => 'product_id'
  belongs_to :buy_order_detail, :foreign_key => 'buy_detail_id'
  before_create :create_storage 

  def create_storage
    Storage.create!(:product_id => self.product_id, :current_quantity => self.quantity, :stg_data => purchase.prc_data)
  end
end