Adding an extension to the URL: Rails

I am creating some link_to xml links in a rails application. How can url display the .xml extension?

Need it to appear as: http://localhost:3000/test/1-testing.xml Currently it appears as: http://localhost:3000/test/1-testing 
+6
url ruby-on-rails hyperlink
source share
2 answers

In Rails 3, assuming your path is foo_path , you want:

 foo_path(:format=>:xml) 

In link_to you can do

 link_to "link text", foo_path(:format => :xml) 

And with additional options:

 link_to "link text", foo_path(:format => :xml), :id=>"foo_id", :class=>"foo_class" 

(This question is old as hell, but I thought I would answer to help anyone who finds this through Google, like me.)

+10
source share

Assuming you want to set a link to an @test instance, try:

 test_url(@test, :format => :xml) 
0
source share

All Articles