Rails: how controller instance variables work

Good morning, As a newbie to both Rails and web development, I don’t know how to formulate my question, so please feel free to rephrase.

I read that a view in Rails receives data for display through instance variables from the controller. I also read that a controller instance is created for each request. So my question is, how does the rails know what representation gets what values ​​do several simultaneous requests take? Since each controller instance is shared, is it appropriate to set values ​​in instance variables?

+7
source share
1 answer

The answer to your question is my friend:

A controller launch is created for each request. Therefore, each request is IE, each user browses firefox, each ajax request, etc. - will initiate a new controller. This is a rule in MVC that says a controller must be stateless for every request. This is your answer.

+10
source

All Articles