Sunday, July 06, 2008

How to: Rails 2.0 and 2.1 resources with semicolons

Rails 1.X used semicolons as method seperators for resources, so you'd get

http://somesite/things/1;edit

Rails 2.X switches this to

http://somesite/things/1/edit

This is nice and all, but some of us have actual client applications which we can't all just upgrade instantly

To make the semicolon-routes still work in rails 2.X, so you don't break all your clients, do this

At the TOP of routes.rb, before the ActionController::Routing::Routes.draw block

# Backwards compatibility with old ; delimited routes
ActionController::Routing::SEPARATORS.concat %w( ; , )

and, at the BOTTOM of routes.rb BEFORE the end

# Backwards compatibility with old ; delimited routes
map.connect ":controller;:action"
map.connect ":controller/:id;:action"

Profit!

No comments: