Adding extension to URL: Rails
I'm setting up some link_to xml views within a rails app. How can the url display the .xml exte开发者_开发知识库nsion?
Need it to appear as:
http://localhost:3000/test/1-testing.xml
Currently it appears as:
http://localhost:3000/test/1-testing
In Rails 3, assuming your path is foo_path
, then you want:
foo_path(:format=>:xml)
In a link_to
, you can do
link_to "link text", foo_path(:format => :xml)
And with more options:
link_to "link text", foo_path(:format => :xml), :id=>"foo_id", :class=>"foo_class"
(This question is old as heck, but I thought I'd answer to help out anyone who finds this via Google, like I did.)
Assuming you want to link to the instance @test, try:
test_url(@test, :format => :xml)
精彩评论