Session nil in view

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

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.

On Feb 7, 10:02 pm, bigbanger [email protected] 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.

On 8 Feb 2008, at 05:30, MohsinHijazee wrote:

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

On Feb 8, 2:17 pm, Frederick C. [email protected]
wrote:

But that piece of code works fine when I browse through my browser in

Thank you very much!