2009-11-09 90 views
6

我在Rails應用中設置了一些link_to xml視圖。 url如何顯示.xml擴展名?向URL添加擴展:Rails

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

Currently it appears as: 
http://localhost:3000/test/1-testing 

回答

0

假設你要鏈接到該實例@test,請嘗試:

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

這是我的鏈接代碼: <%= link_to'Map',{:action =>'map',:id => entry,:format =>:xml}%> 並顯示爲: http:// localhost: 3000/entries/map/1-sample-form?format = xml 它需要是: http:// localhost:3000/entries/map/1-sample-form.xml – Jeffrey 2009-11-09 18:41:09

10

在Rails 3,假設你的路徑是foo_path,然後你想:

foo_path(:format=>:xml) 

link_to,你可以做

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

而且具有更多的選擇:

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

(這個問題是老赫克,但我想我會回答,以幫助任何人誰通過谷歌發現這一點,像我一樣)