Back
[rails] Formatted URLs in SimplyRESTful
Other·Calvin Correli·Jul 26, 2006· 1 minutes

It took me a bit to figure out how to use the formatted_XXX_url named URLs that the SimplyRESTful plugin generates for you. It’s not hard, it’s just not documented, either, and the code isn’t the clearest to read. In fact, I probably wouldn’t have noticed them if it wasn’t for Rick Olson’s Routing Navigator.

So if you have the normal URL for a user like this:

user_url(@user)
=> /users/1

You can say this instead, and it’ll give you the XML version:

formatted_user_url(@user, :xml)
=> users/1.xml

It’s quite simple, really.

By the way, if you want this to work for iCalendar format with .ics extension, you need to add this to your environment.rb, as it’s missing from Rails’ mime_type.rb (I’ll submit a patch once Trac is back in business):

Mime::EXTENSION_LOOKUP["ics"] = Mime::ICS