{"id":29,"date":"2007-04-18T22:56:09","date_gmt":"2007-04-19T02:56:09","guid":{"rendered":"http:\/\/danielroop.com\/blog\/2007\/04\/18\/resful-resources\/"},"modified":"2007-04-18T22:57:14","modified_gmt":"2007-04-19T02:57:14","slug":"resful-resources","status":"publish","type":"post","link":"http:\/\/danielroop.com\/blog\/2007\/04\/18\/resful-resources\/","title":{"rendered":"Resful Resources"},"content":{"rendered":"<p>Over the last two weeks <a href=\"http:\/\/blog.tylerhunt.com\">Tyler<\/a> and I have been coding like mad men, after work to get closer to a feature complete <a href=\"http:\/\/tallyhoh.com\">TallyHoh<\/a> 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.  <\/p>\n<p>I looked for hours and it didn&#8217;t seem that anyone wanted to talk about the topic.  This was very confusing to me seeing as how everyone was writing code like:<br \/>\n<code><br \/>\n&nbsp;&nbsp;def index<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;respond_to do |format|<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html => {}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.xml => {model.to_xml}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;end<br \/>\n&nbsp;&nbsp;end<br \/>\n<\/code><\/p>\n<p>Finally I found <a href=\"http:\/\/seanmountcastle.com\/wp-content\/uploads\/2007\/03\/restful-rails.pdf\">this article<\/a>, which didn&#8217;t address the problem directly but included a small table that mentioned the method.  So thank you Sean Mountcastle, I appreciate your pdf.<\/p>\n<p>For those that are hear because they want to know how to actually write the code.<\/p>\n<p>If you have:<br \/>\n<code><br \/>\n   map.resorces :feeds<br \/>\n<\/code><\/p>\n<p>then you should write something like:<br \/>\n<code><br \/>\n   &lt;%= link_to formatted_feeds_url(:format => :xml) %&gt;<br \/>\n<\/code><\/p>\n<p>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 &#8220;:format&#8221;.<\/p>\n<p>if you were trying to access a specific feed:<br \/>\n<code><br \/>\n  &lt;% @feed = Feed.find(:first) -%&gt;<br \/>\n  &lt;%= link_to formatted_feed_url(@feed, :xml) %&gt;<br \/>\n<\/code><\/p>\n<p>Hope this helps atleast one person not go through the hours of searching I had to, to find this poorly documented method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"http:\/\/danielroop.com\/blog\/2007\/04\/18\/resful-resources\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[22,126,20],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-programming","tag-rails","tag-rest","tag-ruby"],"_links":{"self":[{"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":0,"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/danielroop.com\/blog\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}