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.
One Response to Resful Resources