Angelo
Angelo

Reputation: 905

Ruby on Rails 3 - callbacks not working any more


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?

Upvotes: 1

Views: 430

Answers (1)

apneadiving
apneadiving

Reputation: 115511

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

Upvotes: 2

Related Questions