The 7 main actions we took to improve the Rails stack performance at Justin.tv
Here are the slides of the talk I gave at the San Francisco Rails meetup group yesterday about the work we have done on improving Rails performance at Justin.tv
Enjoy!
Here are the slides of the talk I gave at the San Francisco Rails meetup group yesterday about the work we have done on improving Rails performance at Justin.tv
Enjoy!
Hello there! Almost 10 months without any post due to a very busy period: I moved from Paris to San Francisco.
Ok, so now facts has been said, this will hopefully change! I plan to write a new series of Rails3 posts, starting with a quick one on the new way Rails handles notifications.
The new version of ActiveSupport shipped with Rails brings along a new notification system which is heavily used by Rails3 internarlly. Rails doesn’t write directly to logs anymore, instead of that, it publishes a notification which can be caught by any observers.
In production, Rails will by default publish deprecation warnings through this notification system. Last week I was looking for a way to play with that and didn’t find a clear example on the web, so here is a small snippet of code if you are also looking for a nice way to log your deprecation warnings:
As you know, Rails3 use only UJS (unobtrusive javascript), so for every remote link, Rails3 just add the data-remote attribute to links :
If you want to do ajaxed pagination, there is no easy way with will_paginate to do remote link (or I didn’t find any one), but with Rails3 UJS, there is a little tricks do to this easily !
Here is the haml and jquery code :
This snippet of code just add the attribute data-remote to pagination links. And that’s it ! Our pagination will now be ajaxed
With the upcoming release of Rails3, it’s important to maintain gem/plugins compatibility with both Rails 2.x series and the new Rails 3.x series.
That’s why I wanted to implement specs supporting both versions for one of my plugin.
With a simple rake task, I wanted to run spec for a specific Rails version.
By default, Rspec create this kind of Rakefile :
Here we have the default Rake task : “spec” wich will run specs for our code.
At this point, we need to pass an extra option to spec script in order to specify wich rails version we want to use in our tests.
The way I found to do this is to tricks spec_opts (which is command line options for spec) by assigning to it, a Proc, like this :
Then add two tasks to your Rakefile :
Ok, now we have our three tasks passing Rails version to our spec tests !
Then in your spec_helper.rb file, where you include your dependencies, you just need to retrieve the rails version with this (dirty) piece of code :
Now we have the correct rails version we want for running our tests, so we need to include our dependencies depending on the Rails’ version we want to load.
For this, there is a tricky things with gem method for specify wich version of gem you want to use :
(Example for loading action_controller only, here I use 2.9 version number in order to support Rails3beta)
Here we are, now we can run our tests on both Rails version just with a simple rake task :
Here are just two little issues I encoutered today when I worked on Rails 3 edge routes. I think it can be useful to share them.
I assume you already know changes in routes for Rails3.
(if not, watch: Ryan Bates Screencast about routing in Rails3)
Matching empty route string are now impossible in Rails 3 edge (not in beta yet), so you can not do anymore :
Instead, you need to use root :
Route globbing is a way to catch any action matching a part of an url. It’s useful for catching errors for example.
In Rails 2, it was with connect
In Rails 3, it’s pretty the same, but with match :
Put this snippet at the end of your routes declaration and the ErrorController will be called if not routes match the requested uri.
Remember that you do not need anymore to get the map variable in your route block :
Rails 2:
Rails3, remove the |map| :
Yesterday, the jQuery team has released a new version of its famous javascript library, and again, it’s rock competitors

A good start for succeed your projects, it’s using good tools. And jQuery is one of them.
So, do not wait, and start using the today best javascript library !
Use the jQuery official UJS plugin : http://github.com/rails/jquery-ujs, explanations for usage on another blog : http://blog.datagraph.org/2010/02/jquery-with-rails-3
And do not forget to use the helper csrf_meta_tag in your header in order to output metas for the authenticity token.
Install the drop-in remplacement jrails plugin: http://github.com/aaronchi/jrails