我正在尝试使用客户账单的属性创建任务,下面给出的是
class Supplier < ActiveRecord::Base
has_many :tasks, :dependent => :destroy
after_update :updating_daily_job_task
def updating_daily_job_task
if self.amount.present? && self.date.present?
Task.create(:name => self.supplier_id.to_s, :due => self.date)
end
end
end
任务模型
class Task < ActiveRecord::Base
attr_accessible :name, :due, :complete, :user_id, :supplier_bill_id
belongs_to :supplier_bill, :foreign_key => "supplier_bill_id"
validates_presence_of :name, :due
end
我收到以下错误
undefined method `create' for Rake::Task:Class
谁能告诉我我哪里做错了???预先感谢:)
最佳答案
您应该更改 Task
模型的类名称。将其更改为 SupplierTask
或任何更相关的内容。 Task 在 Rails 内部的某处使用,导致此问题。
关于ruby-on-rails - ruby on Rails 中的 after_update 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11878067/