1.8. Under the
Hood
As shown earlier, each time you submit a URL,
you're creating an HTTP request, which fires a controller action.
Any MVC framework designer needs to decide between reusing the same
controller for each request and creating a new controller copy per
request. Rails does the latter strategy, which it calls
request scope. Each HTTP request
results in a new controller instance, meaning that you'll also get
a new set of instance variables for each HTTP request. That's going
to affect you in at least two different ways:
-
On the plus side, you don't need to worry about
threading in your controllers because each request gets a private
copy of the controller's instance data.
-
On the minus side, it will be harder for you to
share instance data between requests. Specifically, if you set
instance variables in one controller action method, don't expect to
be able to use them in later HTTP requests. You'll need to share
them in a session.
|