You are using the old router DSL !

In some Rails 3 application, I get a somewhat cryptic message in my development log file :

DEPRECATION WARNING: You are using the old router DSL which will be removed in Rails 3.1. Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/

I’ve read the designated article on the (great) EngineYard blog, but I didn’t find anything wrong in my routes file.

I searched for the message in ActionPack source code, found a call to DeprecatedMapper, then search for that and found something interesting in route_set.rb. In the "draw" method, there is a check on the block "arity". WTF is arity ?

The arity method exists on Proc objects to check for "the number of arguments that would not be ignored" (straight from the Ruby documentation).

I understood that the route file must not have any argument in the main (draw) block.

I had to change this

MyApp::Application.routes.draw do |map|
  (…)
end

into

MyApp::Application.routes.draw do
  (…)
end

It’s as simple as that, and then I didn’t have deprecation messages for my router’s syntax anymore.

I guess it wasn’t so easy to find because in EY’s blog post, there is no example with the Proc definition (and only one in the official guide), only examples of routes themselves.

Update : I’ve just found out that there was already a comment on EY’s blog about this exact issue. I guess I’ve not search enough :-/

About these ads
Cette entrée, publiée dans Informatique, est taguée . Bookmarquez ce permalien.

Une réponse à You are using the old router DSL !

  1. euh, avez-vous poster sur mon blog, de l’artisanat et de l’histoire?

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s