This feature is scheduled for: Rails v2.3/3.0
Parallel to the addition of :except and :only options to Rails’ routing comes the removal of all those formatted_xxx named routes. Turns out these routes ate up a lot of memory and served minimal purpose.
So with this routes.rb definition:
1 2 3 |
ActionController::Routing::Routes.draw do |map| map.resources :articles end |
you’ll no longer have any of the formatted_xxx url helpers available. However, you will be able to get the same functionality by passing in a :format option to the base view helper methods:
1 2 3 4 |
# Old => New formatted_article_path(article, :xml) => article_path(article, :format => :xml) formatted_new_article_path(:json) => new_article_path(:format => :json) # etc... |
A minimal change that will have a big impact on the memory consumption of each of your Rails processes – especially if you’ve got a complex app with lots of routes.
If you’re on Edge Rails you’re going to start seeing deprecation warnings where you reference these formatted url helpers, so you’ve got some warning before you have to make the switch.
tags: ruby, rubyonrails

If those eat up so much memory, it sure would be nice to get ride of the _path helpers as well. Or at least be able to turn them off via a config.
@jc I believe those, like most crazy methods in rails, are generated at run time. If you don’t ever call them, they won’t ever take up memory. This is how I understand find_all_by_some_column and friends work, haven’t tested it with the routing helpers to be 100% sure.
Can anyone tell me how I can update to latest rails edge?
@Jamal Run rake rails:freeze:edge on your Rails app root and it will freeze the latest edge version to your app.
Nice! This should cut down on the memory footprint of my thin instances considerably.
@Scott, That’s what she said.
Like everything else that is new in Rails this is great stuff!
I like the way Rubyites are not afraid to make radical changes to code. I think this will eventually nip PHP in the bud.
@Paul, I think one of the reasons they aren’t too afraid to make changes like this is installing old versions of Rails (for legacy apps) is pretty easy and the apps even say what version of rails they were developed with in the config/environment.rb. So if you were to use code that doesn’t work on the newest version, you can pretty easily find out what version to go back to to make it work again. Not to mention the freezing functions for the times you just gotta be sure.
But even with that, PHP is well beyond the “bud” stage alreaqdy. Rails has made PHP development painful to me, but there are still a lot of jobs out there calling for PHP experience. 8^(
i recommend this be backported via a gem or whatever to 2.2 since rails 2.3 probably won’t be out for a long time
@w. andrew loe iii – incorrect. Named route methods and recognizers are defined dynamically when environment loads so you pay the price for mapping them out whether they are used or not.
This is a really great change. Having separate method names for the “formatted” routes always felt like an ugly hack anyways.