[Rails] Re: A Good Tutorial on Params and Variables

Ilya Grigorik
2006-04-30T13:02:24Z

> This works fine within the Controller it was assigned it, but it has a
> Nil value when I try to reference it in other Controllers. You mentioned
> that I need to specify a model. What is the syntax for doing this?
>
> Specifically here is the code:
>
> class UserController < ApplicationController
>   model   :user
>   layout  ''scaffold''
>

You''re alreade doing this in the code above. "model :user" is
the line I
was referring to. Note that for this class, where you set/create the
user object you don''t have to explicitly specify the model :user, but
in
any/all other controllers, this same chunk of bytecode doesnt mean
anything, hence you have to tell it to use ''model :user'' so it
knows
what objects to initialize and how to process that chunk.

So, you can either specify model :user in every other controller that
uses it, or alternatively, if you need it site-wide, put it in the
application.rb which is used to establish site-wide behaviors.