When are you saving the user_id to the session? You need to force a redirect to a login page if there is no session [:user_id] and you should also handle the fact that session[:user_id] may be nil in your is_logged_in? method.
On Apr 29, 1:15 pm, Stephen Fagan <[email protected]> wrote: > Hi all, I've put new code into my app so that an administrator will have > extra privileges (administer users, edit pages). The error is: > > 'Couldn't find User without an ID' > > So the app is looking for a logged in user when the homepage is > accessed. > > Heres my code: > > site/index view: > > <% if is_logged_in? and logged_in_user.has_role?('Moderator') -%> > <%= link_to 'Administer Users', :controller => 'user', :action => > 'show' %> > <%= link_to ' | Edit pages', pages_path %> > <% end %> > > application helper: > > def is_logged_in? > @logged_in_user = User.find(session[:user_id]) > @logged_in_user ? @logged_in_user : false > end > > def logged_in_user > return @logged_in_user if is_logged_in? > > How could I change the code to rectify this? Any help would be greatly > appreciated > > Steve. > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

