Error: MySQL gone away - subclass of model

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs