Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 extension?

Need it to appear as:
http://localhost:3000/test/1-testing.xml

Currently it appears as:
http://localhost:3000/test/1-testing
like image 680
Jeffrey Avatar asked Nov 09 '09 17:11

Jeffrey


2 Answers

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.)

like image 169
Grant Birchmeier Avatar answered Oct 19 '22 21:10

Grant Birchmeier


Assuming you want to link to the instance @test, try:

test_url(@test, :format => :xml)
like image 29
ry. Avatar answered Oct 19 '22 22:10

ry.