hi @ all
I have some information (a value and a percentage number) saved in the
database. for example 5 records. I wrote a model, who’s look like as the
following model:
date value percentagenumber
2006-12-02 10 0.0
2006-12-03 10.5 5.0
2006-12-04 10.71 2.0
2006-12-05 10.6029 -1.0
Every percentage-number are dependent on the value. When I change the
percentage-number 5.0 to 6.0 of the record “2006-12-03”, so every number
are changed who’s younger than the changed one (“2006-12-03”,
“2006-12-04”, “2006-12-05”). How can I realize this in my model? Does
anyone can help me? How can I iterate to my records?
an early reply will oblige
greets ma
Hi !
2006/12/5, M. R. [email protected]:
I have some information (a value and a percentage number) saved in the
database. for example 5 records. I wrote a model, who’s look like as the
following model:
I believe what you want is a callback. In your case, it looks like an
after save callback will do what you want:
class Percentage < AR::Base
after_save :update_related_models
protected
def update_related_models
# Do what you need with the other models here. This will only be
called
# after this model is saved.
end
end
For the full details,
http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html
Hope that helps !
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/
2006/12/5, M. R. [email protected]:
And how can I use this callback for all records?
As soon as the record is saved, the callback will fire. You decide
what to do in the callback.
Bye !
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/
And how can I use this callback for all records?
François Beausoleil wrote:
Hi !
2006/12/5, M. R. [email protected]:
I have some information (a value and a percentage number) saved in the
database. for example 5 records. I wrote a model, who’s look like as the
following model:
I believe what you want is a callback. In your case, it looks like an
after save callback will do what you want:
class Percentage < AR::Base
after_save :update_related_models
protected
def update_related_models
# Do what you need with the other models here. This will only be
called
# after this model is saved.
end
end