On 29 August 2014 20:01, António <ajdacr@gmail.com> wrote:
> Dear all,
>
>
>
> I am a new "Ruby/Ruby on Rails" programmer. I am not sure this is the
> correct forum for my question. If this is not the correct forum, please
> indicate me a more appropriate one.
>
>
>
>
>
> When my application implements a URL, an array, @session, is used in several
> methods of a first controller. The application redirects to another page,
> making a second controller being invoked. This controller does not use the
> array. When the method of the second controller ends, a layout is implicitly
> rendered. The layout has the following code:
>
>
>
> ...
>
> <body>
>
> <% if @session.length == 0 then %>
>
> ...
>
>
>
> I got the following error message when trying to implement the URL:
> undefined method `length' for nil:NilClass.
>
>
>
> What should I do in order to the array be recognized by the second
> controller?
As a newcommer to rails I strongly suggest you work right through a
good tutorial such as railstutorial.org (which is free to use online).
That will show you the basics of rails.
As for your question are you trying to use the rails session variable?
If so then it is session, not @session. If it is a variable of your
own then you cannot directly pass it from one controller to another.
Each request to the webserver starts from a clean slate. Remember,
for example, the server could be shut down and restart between
requests. You must re-calculate your variable at each request. The
exception is the session variable that I mentioned which is passed,
normally, via cookies.
As I said work through a good tutorial before going any further.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsmEN08FJYb_HegnPcVa6MhqU2nLLPw5-Qz_JAJzGqrhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment