2010-08-28 112 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和探討它的輸出。