代码之家  ›  专栏  ›  技术社区  ›  kolrie

Rails 3呈现XML

  •  2
  • kolrie  · 技术社区  · 14 年前

    我有Rails 3应用程序(运行Rails RC1),我有以下控制器:

    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

    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/ree-1.8.7-2010.01@rails3/bundler/gems/
       devise-6754ae7/app/views"
    

    另外,我的ApplicationController非常简单:

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

    我试过从控件中取出布局线,但结果相同。

    plugins/index.html.haml .

    1 回复  |  直到 14 年前
        1
  •  1
  •   Community datashaman    4 年前

    从评论到 respond_with

    当请求的格式为:xml时,respond\u将首先作为person搜索模板/索引.xml,如果模板不可用,它将查看给定的资源是否响应:to \u xml。

    如果两者都不可用,则会引发错误。

    尝试显式调用 @plugins.to_xml 并研究它的输出。