Aug 10

When working with Sinatra + ActiveRecord + MySQL running on the venerable Thin server, you are probably going to see the error after 8 hours(MySQL default connection timeout): “Mysql::Error: MySQL server has gone away” message. The resolution is pretty simple:

class NewApp < Sinatra::Default   

  before do
    ActiveRecord::Base.connection.verify!
  end
...
end #end of Sinatra class

I created a Lighthouse ticket before I discovered the resolution. There are also more technical details here: https://thin.lighthouseapp.com/projects/7212-thin/tickets/101-activerecord-connection-does-not-reconnect-when-using-thinsinatra-but-works-fine-with-just-sinatra#ticket-101-4

Tagged with:
Sep 02

When instantiating a model class this error occurs:

instance = MyModel.new
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.has_key?

This is rectified by placing a super within model class.

def initialize
super
logger.debug("initialize VirtualMta: #{self.class}")
end

Tagged with: