Reputation: 1534
I have a lot of functions that I need to access in my controllers and views.
Where is the best place to put these functions?
Upvotes: 0
Views: 137
Reputation: 270609
Functions used for view formatting across the whole application belong in the ApplicationHelper
, however those helper functions should not perform any controller logic of their own. In other words, they should not be responsible for invoking instances of models or doing anything much with them.
Functions that do invoke models, or functions that supply objects or data that will be used by other controllers, and act on them are more appropriately stored in the ApplicationController
. These would be functions like those needed to access application-wide login state in other controllers, for example.
Upvotes: 1
Reputation: 1398
the best place for such commonly used functions is application_controller.rb. I have used it to put code for checking if a user is logged in to determine if he/she needs to log in again.
Upvotes: 0