1
處理該代碼產生ActiveRecordError:ROR ActiveRecord的屬性與一個回調before_update
回調必須是表示 的方法來調用一個符號,一個字符串是 評價,要調用的塊,或 對象響應於回調 方法「。
before_update :check_instock, :unless => Proc.new { |inventory| inventory.needed.nil? }
def check_instock
if needed < amount
instock = true
else
instock = false
end
end
此代碼爲p在我的庫存模型中,我試圖在調用@ inventory.update_attributes(controller)之前處理一些邏輯。以前,我多次致電@ inventory.update_attributes,導致代碼爲worked,雖然不是簡潔。
乾杯!