Search code examples
ruby-on-railsactioncontroller

How can we Override ActionController in rails to common out certain methods?


I have the authentication code to be available over several Controllers. So I thought of putting the Authentication code in to a SuperClass and then make all the other controllers extend this SuperClass. I then got to know that we can add it in the ActionController class itself. How can we do that? Is there a way to change the pre defined class?


Solution

  • You should add the methods to the ApplicationController class which lives in app/controllers/application_controller.rb and is the direct superclass of all your project's controllers (assuming you created your controllers with script/generate and did not change the superclass).