2009-11-09 6 views
6

Je configure des vues link_to xml dans une application rails. Comment l'URL peut afficher l'extension .xml?Ajout de l'extension à l'URL: Rails

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

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

Répondre

0

En supposant que vous souhaitez créer un lien vers le @test d'exemple, essayez:

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

Ceci est mon code lien: <% = link_to 'Carte', {: action => 'carte',: id => entrée,: format =>: xml}%> Et il affiche comme: http: // localhost: 3000/entrées/carte/1-échantillon-forme? Format = xml Et il doit être: http: // localhost: 3000/entrées/map/1-sample-form.xml – Jeffrey

10

Dans Rails 3, en supposant que votre chemin est foo_path, alors vous voulez:

foo_path(:format=>:xml) 

Dans un link_to, vous pouvez faire

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

Et avec plus d'options:

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

(. Cette question est vieille comme diable, mais je pensais que je répondrais à aider toute personne qui trouve cela via Google, comme je l'ai fait)

Questions connexes