Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When will an instance of a controller be created?

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?

like image 794
phnah Avatar asked Aug 03 '11 04:08

phnah


1 Answers

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

like image 128
house9 Avatar answered Oct 23 '22 22:10

house9