Search code examples
ruby-on-railsrubyruby-on-rails-3before-filter

Correct place for rails app-wide method that will be accessible to before_filter


I have a couple of methods being fired by each request by before_filter. I've tried putting these methods in several places but ended up using them in a file under lib and that being the only way that worked. Where is the correct place to put these methods? Ideally I'd like to automatically have these accessible to every controller w/o including anything else.


Solution

  • You can put the methods used by several controllers in the ApplicationController. If most requests must execute this before_filter, put it also in the ApplicationController, and you can ignore the filter for specific actions with skip_before_filter. An example is available here.