Tag Archives: rails

The Rails Grim Reaper

After upgrading to Rails4, I started to see this error ActiveRecord::StatementInvalid: Mysql2::Error: Lost connection to MySQL server during query: in my logs. It seemed random in some places (normal, but generally larger than average queries), and less random in others (high failure rate in long running queries, e.g. in workers). It turns out, I had   …Continue Reading


Puma on Heroku with MRI

Or, How to use Puma like Unicorn I’ve been reading some very good things about Puma (all-Rack stack, proper thread support, & more). I gave it a try with the thread-friendly Rails4, on the thread-friendly Rubinius. To my surprise, the heroku+rails4+puma+rubinius performance was woeful. I’m not sure what I got wrong, but I was seeing   …Continue Reading


Announcing: gs-apns, a new fork of the apns gem.

For the last year Geospike has been using jtv-apns, itself a fork of apns. Our needs have grown, and today I announce our own fork of the APNS gem, name ‘gs-apns’. Gem on rubygems. Code & docs on github. The gs-apng gem continues the good work of James Pozdena and Paul Gebheim with some key   …Continue Reading


Changes to how Rails 3.2.13 and 4.0 encodes unicode in JSON

Heads up: how Rails handles unicode in JSON has changed in rails 3.2.13 and 4.0. Previously unicode characters would be encoded with \u1234 notation. This encoding was actually a bit buggy, anything over two bytes (e.g. outside the Basic Multilingual Plane) would not render correctly1. With 3.2.13 and 4.0, Rails now just passes through UTF-8.   …Continue Reading


Fixing `Could not find a JavaScript runtime (ExecJS::RuntimeError)` Without Another Gem

I didn’t want to add yet another gem to my gemfile, especially one with native dependancies that is going to mess with all the other environments where this app is used (Mac dev, windows dev, Heroku). Since Mac OS X and Windows have a JS runtime shipped by default, and heroku has it’s magic, only   …Continue Reading


Migrating data in a Rails migration

Turns out it’s easy to whack any old piece of code into the migration for migrating your data, for example these work well for some arbitrary SQL statements (I used UPDATE ones…) ActiveRecord::Base.connection.select_one(‘SELECT COUNT(*) FROM mytable’) ActiveRecord::Base.connection.execute(‘SELECT * FROM mytable’) Thanks revgeorge.


Posting to Rails with AJAX

Don’t forget your csrf token! How to do it in Javascript. The token itself can be retrieved in Rails with: session[:_csrf_token]


Rescuing HTTPClient Exceptions

I have a need in a rails app to rescue just exceptions raised due to fairly common situations in downloading data from URLs. Catching all exceptions is bad, as exceptions in my code are treated the same as connection errors, and not passed to my standard exception handling (HTTP 500, plus email to me). From   …Continue Reading


Mysql::ProtocolError with ruby-mysql

Was getting a “Mysql::ProtocolError” when running the ruby-mysql gem with the 64bit version of MySQL on Mac OS X 10.6. Stackoverflow said to downgrade the version (done – modified the Gemfile to specify the exact version), but I still had to modify one line of code to get it to work. The line of code   …Continue Reading


Tales of PDF Generation in Rails

Last week’s “inflight project” (that is, some fun code I hack out while in the air) was to do some custom PDF generation in Rails. That is, a special view to render a PDF. There appear to be two main approaches to this currently in rails: PDFKit (which uses the wkhtmltopdf binary, itself based on   …Continue Reading