hi, i have 4 different controllers that are basically doing the same
thing but just passing different parameters to the model functions. can
i just place all the code in the application.rb file?
so when an action comes in from a view, it goes to the controller, and
then to the application.rb, and then passed to the model?
Yes.
----- Original Message -----
From: “mixplate” [email protected]
To: [email protected]
Sent: Monday, November 20, 2006 9:04 AM
Subject: [Rails] question about putting code in application.rb…
mixplate wrote:
hi, i have 4 different controllers that are basically doing the same
thing but just passing different parameters to the model functions. can
i just place all the code in the application.rb file?
so when an action comes in from a view, it goes to the controller, and
then to the application.rb, and then passed to the model?
Not exactly.
All controllers inherit from the class ApplicationController which
resides your application.rb.
So any action will be handled by your controller unless it doesn’t have
that action defined. If your controller has no action, it will use any
action from it’s parent’s class, in this case ApplicationController.
It will never go to the model searching for methods, ever.
In short, any functionality you want it all controller, put in
application.rb.
If you want this functionality in all controllers, then it should go in
application.rb.
If you want it in only some controllers but not others, you could create
a
new controller
class AdminController< ApplicationController
before_filter :admins_only
end
Then inherit from that instead
class SomeOtherController < AdminController
end
You could also experiment with using modules to share code between
controllers.