[Rails] Re: Re: templates and arrays
Bruce Balmer
brucebalmer at mac.com
Wed Dec 14 14:01:24 GMT 2005
Brian:
Thanks. Your explanation really cleared up something that has been
mystifying me.
bruce
On 13-Dec-05, at 7:23 PM, Ezra Zygmuntowicz wrote:
>> Brian V. Hughes wrote:
>>> Bruce Balmer wrote:
>>>> only instance variables are "magically" passed from the
>>>> controller to
>>>> the view. So if you have product in your controller and you try
>>>> to use
>>>> product in your view - it won't work. I had the same experience
>>>> myself.
>>>
>>> Just to try and clear this up, a bit, there's nothing magical about
>>> instance
>>> variables. They simply have a wider scope than a local variable.
>>> If it
>>> helps,
>>> think of instance variables as global variables that exist for a
>>> single
>>> HTTP
>>> request. Once they are defined, during the request, they are
>>> available
>>> to all
>>> subsequent code snippets that need to access them. If you define
>>> them in
>>> the
>>> controller (which is probably best, since the controller is
>>> called very
>>> early
>>> on) they are then usable by the main view, all partial views, and
>>> any
>>> helpers
>>> those views need to call.
>>>
>>>> but @product in the controller and the view WILL work. I don't
>>>> understand why.
>>>
>>> Define a variable @product in the controller and the view is able to
>>> access the
>>> same variable, yes.
>>>
>>> -Brian
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20051214/2a9ea603/attachment.html
More information about the Rails
mailing list