2011-08-16 73 views
1

嗨,人。Ruby on Rails 3 - 回調不再工作

我有一個大問題。直到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,而非原型

可能是這個問題唯一的變化?

回答

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 
+0

我已經試過,並沒有爲我工作。我只發佈了部分代碼,我還有其他回調和驗證,可能是由於回調和驗證之間的一些不兼容問題而發生的問題? – Angelo

+0

我試過調試,結果我得到的回調是零...我不明白。 – Angelo