Reputation: 73
Good Morning, As a beginner to both Rails and web development, I don't know how to articulate my question so please feel free to rephrase.
I read that that a view in Rails gets the data to display via instance variables from the controller. I also read that an instance of the controller is created for each request. So my question is how does rails know which view gets which values assuming multiple simultaneuos requests? Since each controller instance is shared, is it wise to put values in the instance variables?
Upvotes: 7
Views: 2788
Reputation: 1894
The answer is in your question my friend :
An intance of the controller is created on every request. Therefore, each request - IE each user browsing in firefox, each ajax request etc... - will instanciate a new controller. It's the rule in MVC that says a controller should be stateless for each request. That's your answer.
Upvotes: 11