deeraj
deeraj

Reputation: 148

after_update callback in ruby on rails

I am trying to create a task by using attributes of the customer bill and given below are the

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

task model

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

and i am getting the following error

undefined method `create' for Rake::Task:Class

can anyone tell me where i am doing anything wrong??? thanks in advance :)

Upvotes: 2

Views: 1266

Answers (2)

Amar
Amar

Reputation: 6942

You should change the class name for the Task model. Change it to SupplierTask or anything more relavant. Task is used somewhere in Rails internals, which causes this issue.

Upvotes: 3

Nick
Nick

Reputation: 2478

I'm not 100% sure on this one but it looks like when you reference the Task class you're picking up the wrong class (you're getting the one from the Rake module). You could try changing the name of your task model and see whether that removes the clash

Upvotes: 1

Related Questions