开发者

Adding extension to URL: Rails

开发者 https://www.devze.com 2022-12-11 02:46 出处:网络
I\'m setting up some link_to xml views within a rails app. How can the url display the .xml exte开发者_开发知识库nsion?

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

精彩评论

暂无评论...
验证码 换一张
取 消