Chen Kinnrot
Chen Kinnrot

Reputation: 21015

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)

Upvotes: 22

Views: 4867

Answers (1)

mahemoff
mahemoff

Reputation: 46509

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.

Upvotes: 27

Related Questions