使用默认路由,request/posts /:id将映射到"show"操作:format => "html".我在show动作中使用了一些xhtml元素,除非将:content_type设置为xml,否则这些元素无法正确呈现.我目前通过渲染show.xml.erb并手动设置content_type来解决这个问题,如下所示:
format.html { render :template => "/posts/show.xml.erb",
:locals => {:post => @post}, :content_type => "text/xml" }
Run Code Online (Sandbox Code Playgroud)
这看起来很傻.我如何更改routes.rb以便/ posts /:id被路由format=>"xml"?谢谢.
我已经看到这些错误很长时间了,但没有发现问题:
ActionView::MissingTemplate: Missing template pages/home, application/home with {:locale=>[:en], :formats=>["*/*;"]}
用户代理始终是 MSIE6(这是我之前放弃的部分原因)。
重现: curl -H "Accept: */*;" -I http://localhost:5000
有谁知道怎么修?
编辑
curl -H "Accept: */*" -I http://localhost:5000作品。仅当格式设置为*/*;(注意分号)时,它才起作用。
更新
我试图修改Mime:ALL的建议的意见,但无法拥有它同时接受*/*,并*/*;在同一时间。我看到的一个解决方案是在不存在或格式错误的 mime 类型时修补请求的处理方式,但我不确定如何处理。这个答案提供了一个线索,但我仍然没有。
更多更新
我仍然看到这些错误和更多。一个新的是:formats=>["hc/url;*/*"](Firefox)。我很惊讶这不会影响其他任何人,我认为我的代码中没有任何会导致不常见错误的特定内容。
你能默认所有路线json吗?
我有以下api范围,但我想知道你是否可以在全球范围内做同样的事情?
scope :api, defaults: {format: :json} do
get "/search(/:query)(/:location)" => "search#index"
end
Run Code Online (Sandbox Code Playgroud)
例如,所有user资源也将默认为json
resources :users
Run Code Online (Sandbox Code Playgroud)