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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi ! 2006/12/5, M. R. <rails-mailing-list@andreas-s.net>:> 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And how can I use this callback for all records? François Beausoleil wrote:> Hi ! > > 2006/12/5, M. R. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: >> 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 >-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
2006/12/5, M. R. <rails-mailing-list@andreas-s.net>:> 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---