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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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
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.
This topic is locked and can not be replied to.