Custom update method problem

I’ve got group of updates that I call in certain cases. They update
data in different tables if specific conditions are met when a new row
is saved to the “drive” (see below) database table. I suspect that I
should make a method out of the group and reuse it in all the cases,
but when I do that I’m getting errors that one of the objects is null.
Here’s what the method should look like, but it’s not functioning when
called.

def goal_achieved_update
goal.update_attributes (:achieved => 1,
:achieved_on => @drive.drive_date)
@best_drive.update_attributes (:state => 1)
@drive.update_attributes (:state => 8)
end

Should I be passing arguments to this method? Or perhaps it should be
in the model and not in the controller?

Any direction to sample code where a update method is created are
reused would be greatly appreciated.

Thanks for any help!!
Bob.

Bob wrote:

I’ve got group of updates that I call in certain cases. They update
data in different tables if specific conditions are met when a new row
is saved to the “drive” (see below) database table. I suspect that I
should make a method out of the group and reuse it in all the cases,
but when I do that I’m getting errors that one of the objects is null.
Here’s what the method should look like, but it’s not functioning when
called.

def goal_achieved_update
goal.update_attributes (:achieved => 1,
:achieved_on => @drive.drive_date)
@best_drive.update_attributes (:state => 1)
@drive.update_attributes (:state => 8)
end

Should I be passing arguments to this method? Or perhaps it should be
in the model and not in the controller?

Any direction to sample code where a update method is created are
reused would be greatly appreciated.

Thanks for any help!!
Bob.

Bob,

My guess is that goal is the null object; it is a local variable as
written (without a preceding glyph), but is not initialized within this
context. Perhaps you mean @goal if it is an instance variable?

David B. Williams
http://www.cybersprocket.com