ApplicationController is practically the class that any other controller in your application inherits from (although this is not necessary in any case).
I agree not to spoil it with too much code and keep it clean and tidy, although there are some cases where ApplicationController will be a good place to put your code. For example: if you work with several language files and want to set the locale based on the requested URL, do this in your ApplicationController:
before_filter :set_locale def set_locale I18n.locale = params[:locale] || I18n.default_locale end
This will save you from a headache when setting up the language in each controller separately. You do this once, and you have a locale installed throughout the system.
The same can be said for the famous protect_from_forgery , which can be found in the default ApplicationController for the new rails application.
Another use case can save all exceptions of a certain type in your application:
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found private def record_not_found render :text => "404 Not Found", :status => 404 end
In general, if you have a feature that all other controllers will definitely use, the ApplicationController may be a good place for it.
source share