ruby-on-rails-3

Rails controller lifecycle


I want to know a little about the object lifecyle in rails, can I count on new instance per request?, Is it true to say that each web request creates a new controller instance?(by default)


Solution

  • Yes, you can rely on a fresh controller instance per request.

    RailsGuides:

    When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the method with the same name as the action.