I have to provide a link based on a value stored in session object but getting the session object nil in the view. Following is the error message: ActionView::TemplateError: You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] On line #13 of admin/details/new.rhtml 10: <% if params["for_entity"] %> 11: <%= submit_tag(t("quick_submit"), :name => "quick_commit")%> | 12: <%end%> 13: <%=link_to t("cancel"),session["return-to"] %> 14: <% end -%> 15: 16: <script type="text/javascript"> Can anyone guide me how the session object is fine in the controller and the very next instant its nil in the view? Regards, Mohsin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The session object is not accessible in a view, it is only available in the controller layer. But you can save the session value in an instance variable in your controller and reference that instance variable in your view instead. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 7, 10:02 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The session object is not accessible in a view, it is only available > in the controller layer. But you can save the session value in an > instance variable in your controller and reference that instance > variable in your view instead.But that piece of code works fine when I browse through my browser in the development mode. This only happens when I run the tests. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Feb 2008, at 05:30, MohsinHijazee wrote:> > > > On Feb 7, 10:02 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> The session object is not accessible in a view, it is only available >> in the controller layer. But you can save the session value in an >> instance variable in your controller and reference that instance >> variable in your view instead. > > But that piece of code works fine when I browse through my browser in > the development mode. This only happens when I run the tests.Would have been useful if that''s what you had said? I recall a recent discusscion on rails core where it emerged that normally the session is a HashWithIndifferentAccess (so session["return-to"] and session[:return-to] are the same thing, but in tests it was just a regular hash( and so only session[:return-to] worked). Use session[:return-to] instead of the string form and you should be ok. Fred> > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrai--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 8, 2:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8 Feb 2008, at 05:30, MohsinHijazee wrote: > > > > > On Feb 7, 10:02 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> The session object is not accessible in a view, it is only available > >> in the controller layer. But you can save the session value in an > >> instance variable in your controller and reference that instance > >> variable in your view instead. > > > But that piece of code works fine when I browse through my browser in > > the development mode. This only happens when I run the tests. > > Would have been useful if that''s what you had said? I recall a recent > discusscion on rails core where it emerged that normally the session > is a HashWithIndifferentAccess (so session["return-to"] and > session[:return-to] are the same thing, but in tests it was just a > regular hash( and so only session[:return-to] worked). Use > session[:return-to] instead of the string form and you should be ok. > > Fred >Thank you very much!> > > > --~--~---------~--~----~------------~-------~--~----~ > > You received this message because you are subscribed to the Google > > Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrai--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---