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?

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.