Forum: Ruby on Rails Error: MySQL gone away - subclass of model

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Neubyr N. (Guest)
on 2009-04-23 20:58
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

  def current_user_and_role
    if session[:user].nil? # used null object pattern
      @currentuser =
      @currentusername = 'Unassigned'
      @currentrole = 'anonymous'
      @currentuser = User.find(session[:user])
      @currentusername = @currentuser.username
      @currentrole =

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):
log' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record
... ...
/app/controllers/application.rb:13:in new'

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?

This topic is locked and can not be replied to.