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

发布于 2024-11-30 08:49:22 字数 611 浏览 0 评论 0原文


大家好。

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

回调如下:

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 而不是 prototype

这可能是问题所在吗?


Hi people.

I have a big problem. Untill 2 weeks ago, my code was working fine, but today I realize that some callbacks are not working any more.

The callback is the following:

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

The idea is that everytime a Detail_purhase is created, a storage with the same product should be created automatically after that.

But now it is not working, the only change is now I'm using jquery instead of prototype

Could that be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窗影残 2024-12-07 08:49:22

奇怪的是它起作用了。正确的语法是:

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

Weird it worked. Correct syntax is:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文