Layout switching and varialbes

I have a problem with a function, I tried to achieve a layout
switching according to the user level that’s logged in
(session[:user_level] )
the function looks like this

def switch_layout
case session[:user_level].to_i
when 3 : render :layout=> ‘admin’
when nil : render :layout=> ‘application’
else render :layout=> ‘nonadmin’
end
end

The problem that i have when i use a function like list which uses a
variable @users = User.find(:all)

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each

In the view there is

<% for user in @users -%>

I don’t know why this is happening …
Any ideas?

Because you’re calling render, anything you define thereafter will not
really be defined in the code.

Try calling just layout :admin instead.

On Jan 3, 2008 2:50 AM, Adam [email protected] wrote:

else render :layout=> ‘nonadmin’
In the view there is

<% for user in @users -%>

I don’t know why this is happening …
Any ideas?


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

Yep that was it :slight_smile:
Thanks

OK I remembered why I used ‘render :layout’, the problem was that
before_filter didn’t worked when i called ‘layout’ inside of it…
now i made just layout :switch_layout.
Thanks for the reply.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs