2010-08-28 129 views
2

我的Rails 3应用程序(运转轨道RC1),我有以下控制器:Rails 3中渲染XML

class PluginsController < ApplicationController 
    respond_to :html, :xml, :json 

    def index 
    @plugins = Plugin.all 
    respond_with(@plugins) 
    end 
end 

如果我尝试呈现http://localhost:3000/plugins它工作正常,显示我的HTML版本。如果我尝试获得http://localhost:3000/plugins.json,它也会正确地向我发送JSON响应。

但是,如果我尝试http://localhost:3000/plugins.xml,我得到以下错误:

Template is missing 

Missing template plugins/index with {:locale=>[:en, :en], :formats=>[:xml], 
:handlers=>[:rjs, :haml, :erb, :rhtml, :builder, :rxml]} in view paths 
"/Users/fcoury/Projects/backend/app/views", 
"/Users/fcoury/Projects/backend/vendor/plugins/haml/app/views", 
"/Users/fcoury/.rvm/gems/[email protected]/bundler/gems/ 
    devise-6754ae7/app/views" 

而且,我的ApplicationController很简单:

class ApplicationController < ActionController::Base 
    protect_from_forgery 
    layout 'application' 
end 

我试图从控制取出轮廓线,但结果相同。

不知道它是否相关,但我使用HAML,我只有一个视图文件,名为​​。

任何想法,为什么会发生这种情况?

回答

1

从到respond_with方法的注释:

When a request comes with format :xml, the respond_with will first search for a template as person/index.xml, if the template is not available, it will see if the given resource responds to :to_xml.

If neither are available, it will raise an error.

尝试显式调用@plugins.to_xml和探讨它的输出。