Restful routing link_to format

358 views
Skip to first unread message

Michael Rigart

unread,
May 25, 2008, 8:16:38 AM5/25/08
to rubyonra...@googlegroups.com
Hi,

I can't seem to find how to define the format in my links. My link looks
like this now:

<%= link_to 'Show', resource_path(@resource) %>

But how do I specify the format? Do I realy need to create the url
myself?

Thank you in advance.
--
Posted via http://www.ruby-forum.com/.

Ryan Bigg (Radar)

unread,
May 25, 2008, 8:22:19 AM5/25/08
to rubyonra...@googlegroups.com
resource_path(@resource, :format => :xml)
--
Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg

Michael Rigart

unread,
May 25, 2008, 8:34:25 AM5/25/08
to rubyonra...@googlegroups.com
Ok, I thought is was this way. But how can I get the url format like

xxx.xml and not like

xxx?format=xml ?

I have

map.connect ':controller/:action/:id.:format'

specified in my routes.rb

Thank you for the quick reply btw

Wildtangent

unread,
May 25, 2008, 9:01:31 AM5/25/08
to Ruby on Rails: Talk
if you do rake routes you should see there are a bunch of additional
routes like

formatted_resource_path

you can use those to specify a path to an xml, rss etc file e.g.

link_to('Show XML', formatted_resource_path(@resource, :format
=> :xml))

Think that should work...

Joe



On May 25, 1:34 pm, Michael Rigart <rails-mailing-l...@andreas-s.net>
wrote:
Reply all
Reply to author
Forward
0 new messages