I have an authorization control which requires current user name (@currentuser.can_update?) to check permissions. The current user info is taken from the sessions and if no user is logged in , i.e., is session has a nil entry for user then I am assigning anonymous user as follows: def current_user_and_role if session[:user].nil? # used null object pattern @currentuser = Anonymous.new @currentusername = 'Unassigned' @currentrole = 'anonymous' else @currentuser = User.find(session[:user]) @currentusername = @currentuser.username @currentrole = @currentuser.role.name end end The Anonymous class is a sub-class of user model. The problem is while using wget or curl command. This occurred while testing and in implementing functionality to generate static html archive. I get an error like: ActiveRecord::StatementInvalid (Mysql::Error: MySQL server has gone away: SHOW FIELDS FROM users): /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:147:in log' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record ... ... /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2126:ininitialize' /app/controllers/application.rb:13:in new' /app/controllers/application.rb:13:incurrent_user_and_role' This does not occur if I place my static archival code in models. However, it spits out this error if static archival is done in controller. So how should I implement this to set current user to logged in or anonymous user? - CS.
on 2009-04-23 18:58