Lars Pind

internet software, coaching, and entrepreneurship

Lars Pind - internet software, coaching, and entrepreneurship
Check out Coach TV, my video blog on happiness and personal development for geeks.

[rails] Formatted URLs in SimplyRESTful

July 26, 2006 · See comments

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

blog comments powered by Disqus

Comments ↓

  • 1 DHH // Jul 26, 2006 at 06:35 PM

    Committed the fix already ;)
  • 2 Lars Pind // Jul 26, 2006 at 09:04 PM

    Thanks, David. I'll just post patches here from now on, then. Who needs Trac, anyway ;)