validates_length_of byte counting gotcha
Watch out for validates_length_of if you need to make sure a string is a certain number of bytes long. For example, SMS messages can be no longer than 160 bytes in length. I recently got bit by this because some unicode “curly” quotes...
Testing HTTP Authentication
If you ever need to test HTTP Authentication in your functional tests, here is how you do it:
1
2
3
4
5
6
def test_http_auth
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(&quo...
Launching Rails projects, an open call for lessons learned
I’m working on my presentation for Rails Underground and was hoping to solicit a few tips from other people in the industry.
Have you launched a Ruby on Rails application recently? Are there some things that you wish you had known beforehand?
Mind sharing? You can email me with your story at robby+launchstory@planetargon.com....
Adding Routes for Tests
I like to be extremely judicious with use of routes. Fewer routes means less memory consumption and fewer confusing magical methods.
I always delete the default route map.connect ':controller/:action/:id' (you should too, otherwise all ...
JavaScript gotcha: storing objects in an associative array
I just ran into a tricky gotcha in JavaScript.
I was trying to store some objects in an associative array. Based on my experience with Java, Ruby, and other languages, I expected that given code like this:
1
2
3
4
5
6
7
var dict...
Today’s hard-won lesson
An float subtracted from an integer results in a float. When typecast by ActiveRecord, this is converted to an integer.
validates_numericality_of with :only_integer => true results in a rather obscure error message if a non-integer i...
Launching Ruby on Rails projects, a checklist
As mentioned in a recent post, I’m hoping to share some lessons that were learned throughout the process of launching a client project. Over the past few years, we’ve been part of several dozen client projects and the big launch date is always an anxiety-filled, yet exciting point for the client and our team....
Plugin I Cannot Live Without
The Enhanced Rails Migrations plugin was written to end the constant battle we had with clashing names in db migrations within our large development team. We tried everything: special commit policies, rake tasks, even claiming the next migration number...
Moving models to a different database
There many reasons to use multiple databases (DBs) and when this is done, there is often a case when a model needs to be moved from one DB to another. The impetus could be that part of the data is referential and this is being reflected by moving it to...
DRYing Models via Acts As
ActsAs is an idiom familiar to every Rails developer, which makes it a good candidate for a shared functionality between models. Using it as early in the game as possible allows one to work on its functionality without a need to touch the code in multi...

