使用默认路由,请求/ posts /:id被映射到:format => "html"
的“show”操作。我在我的show动作中使用了一些xhtml元素,除非:content_type被设置为xml,否则无法正确呈现。我目前得到解决此通过渲染show.xml.erb和手动设置的CONTENT_TYPE如下:如何在Rails中设置路线的默认格式?
format.html { render :template => "/posts/show.xml.erb",
:locals => {:post => @post}, :content_type => "text/xml" }
这似乎是愚蠢的,但。我如何更改routes.rb
以便/ posts /:id与format=>"xml"
路由?谢谢。
您的问题对模型感到困惑:您有地块或帖子吗? – tomeduarte
哎呀,对不起。它的一个模型,称它为帖子。 – Saucerful