Search code examples
ruby-on-railsactioncontroller

Rails ActionController Execute Same Code for Every Action


To the rails experts out there I was wondering where/how you would execute the same code for every action in your web application? If you can point me to an article or provide a short code snippet I would greatly appreciate it.

Thanks in advance to anyone who can help.


Solution

  • Use a filter in your ApplicationController to run the code for every action in your application. All your controllers descend from ApplicationController, so putting the filter there will ensure the filter gets run.

    class ApplicationController
      before_filter :verify_security_token
      def verify_security_token; puts "Run"; end;
    end