views:

39

answers:

3

I have a method which runs several rake commands.

Does this method belong in the controller or in the model?

My intention is to run this method upon every Save or Update

A: 

This belongs in the models, write an Observer that will observe the appropriate model, and put this action there...

http://api.rubyonrails.org/classes/ActiveRecord/Observer.html

rmk
A: 

Save and Update are model operations, so I'd put it there.

Thom Smith
You'd put it in the model and call the method from the controller?
Marco
If it's to be called on every save and update, follow fd's advice and use filters to have them called automatically by the model.
Thom Smith
A: 

You can use a before_save or after_save filter in the model to call arbitrary code, which could include a rake task I guess (I wouldn't do anything too heavyweight though since it could harm the responsiveness of your application).

fd