Roop says

I created gravity?

Roop says header image 1

Resful Resources

April 18th, 2007 · 1 Comment

Over the last two weeks Tyler and I have been coding like mad men, after work to get closer to a feature complete TallyHoh beta. One of annoying things I came across when I was making the transition to Resful Rails, was attempting to set a format using the special path/url methods.

I looked for hours and it didn’t seem that anyone wanted to talk about the topic. This was very confusing to me seeing as how everyone was writing code like:

  def index
    respond_to do |format|
      format.html => {}
      format.xml => {model.to_xml}
    end
  end

Finally I found this article, which didn’t address the problem directly but included a small table that mentioned the method. So thank you Sean Mountcastle, I appreciate your pdf.

For those that are hear because they want to know how to actually write the code.

If you have:

map.resorces :feeds

then you should write something like:

<%= link_to formatted_feeds_url(:format => :xml) %>

that would generate a link like http://%yourdomain%/feeds.xml. Just as an asside, I believe :format is the only required parameter to this method, so I think you can exclude “:format”.

if you were trying to access a specific feed:

<% @feed = Feed.find(:first) -%>
<%= link_to formatted_feed_url(@feed, :xml) %>

Hope this helps atleast one person not go through the hours of searching I had to, to find this poorly documented method.

Tags: , ,

Filed Under: programming

1 response so far ↓

  • 1 Neil // Jul 5, 2007 at 11:43 pm

    Thanks for this article! I also could not find this info anywhere else. These path/url methods are not documented very well. Or if they are, I don’t know where.

Leave a Comment