1
我試圖阻止與另一個記錄有關係的記錄被刪除。我可以停止刪除,但不會發送我希望的閃光消息!無法從模型方法發送Flash消息
class Purchaseitem < ActiveRecord::Base
before_destroy :check_if_ingredient
...
def check_if_ingredient
i = Ingredient.find(:all, :conditions => "purchaseitem_id = #{self.id}")
if i.length > 0
self.errors.add(:name)
flash.now[:notice] =
"#{self.name} is in use as an ingredient and cannot be deleted"
return false
end
end
這將阻止該刪除wihthout閃光燈線,當我添加它,我得到:
未定義的局部變量或方法'閃光」爲#
任何幫助將不勝感激!