hi all,
i am getting following error ,i can’t figure it out why and from
where
it is coming ?
please help me out to resolved this error if anyone knows about this
issue.
i am using following env.
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 #61 of
app/views/layouts/main_bk_layout.rhtml:
58: <%if @session != nil%>
59:
hi all,
i am getting following error ,i can’t figure it out why and from where it
is coming ?
It would help if you had not cropped the top of the error which tells
you exactly which line is causing the error :-/
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 #61 of
app/views/layouts/main_bk_layout.rhtml:
58: <%if @session != nil%>
59:
hi Michael ,
this full trace of the error below.i am new in ROR ,so can you tell me
how
to set session in ROR?
and if set session is coming null then can set it?
i give you the brief of my project :-
in my project the main rhtml is main_bk_layout.rhtml into which the one
user_login.rhtml is called.
but when i hitting url on local host it will give the error for nil
session
for user.
full error trace:-
Processing LoginController#user_login (for 127.0.0.1 at 2011-12-16
13:40:23) [GET]
Rendering template within layouts/main_bk_layout
Rendering login/user_login
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 #61 of
app/views/layouts/main_bk_layout.rhtml:
58: <%if @session != nil%>
59:
Processing LoginController#user_login (for 127.0.0.1 at 2011-12-16
13:40:27) [GET]
Rendering template within layouts/main_bk_layout
Rendering login/user_login
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 #61 of
app/views/layouts/main_bk_layout.rhtml:
58: <%if @session != nil%>
59:
Please don’t top-post. I can’t make you not do it, but I can decline
to reply in future :-/
this full trace of the error below.i am new in ROR ,so can you tell me how
to set session in ROR?
and if set session is coming null then can set it?
I have no idea what you mean “set session”. You have an instance
variable called “@session”, which you’re using in a way that makes me
think it’s a hash.
62:
63: <%end%>
64: <%end%>
Okay… after a second read through the confusion becomes clear. The
error tells you that line 61 is the problem - and shows it is where
you’re accessing “@session[‘user’]” - but looking at the conditional
code, you’re checking if @session is not nil and performing a block
in that event, and then in your “else” block (where @sessionis
nil), you access @session, which obviously crashes because @session is
nil.
I think you need to review the logical flow of the code.
I don’t know what @session is or is supposed to be, but you’ve got
your if statement back to front - you’re trying to access @session[‘user’] when @session is nil
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.