Reputation: 1781
I'm learning Ruby on Rails currently and I'm wondering when an instance of a controller class is created. An instance for each action request? Or one instance that is shared between one client's requests?
I can see there are instance variables in the controller class and they are shared with the view, so I think that a controller instance is created on each action request. Am I right?
Upvotes: 10
Views: 1191
Reputation: 20614
Yes, each http request from a client will create a new controller instance and call that action method on it. The controller instance variables will be accessible to the view.
Check rails guides for more detail: http://guides.rubyonrails.org/action_controller_overview.html
Upvotes: 8