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? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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 <anlauf.adam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yep that was it :) Thanks On 3 Sty, 00:12, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > 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? > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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. On 3 Sty, 00:12, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 <anlauf.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > 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? > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---