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?


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.

  • Thanks. I assumed that each request might be handled by a new thread so the instance variables will be shared (like servlets in Java) – rob Apr 8 '11 at 16:23

Your Answer

