Richard77
Richard77

Reputation: 21621

Activerecord: How to add functionality that responds to the saving or updating event?

here's the Activities model

class Activity < ActiveRecord::Base
  belongs_to :user
  attr_accessible :week, :day, :bcalor, :bicycl, :ccalor, :foodid, :jog, 
                  :lunges, :pushups, :situps, :squats
end 

I'd like to add functionality, such as, after I save or update a activity, I be able to update the summary all the acitities. In .NET we have stuff like OnModelUpdating and OnModelUpdated. How do I accomplish the samething using activerecord?

Thanks for helping

Upvotes: 0

Views: 38

Answers (1)

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9691

In Rails, they are called callbacks. Here you go: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

Upvotes: 1

Related Questions