2010-06-15 45 views
0

我正在使用一個Rails 3控制器,它有一個非常具體的,有限的目的,我需要的只是它的respond_to:json。如何在ActionController :: Metal中包含Responder在Rails 3中?

這截屏說,我的控制器可以從ActionController的金屬::繼承,然後只包括功能我需要的東西更快: http://rubyonrails.org/screencasts/rails3/action-controller

當我的控制器看起來是這樣的:

class FoldersController < ActionController::Metal 
    respond_to :json 
    def all 
    respond_with Folder.all 
    end 
end 

我得到的錯誤:

undefined method `respond_to' for FoldersController:Class 

我試過包括Responder,ActionController :: Responder,Act ionController :: Metal :: Responder,但它們都不起作用。我包括什麼來獲得這個響應者功能?

回答

1

您需要包含更多的類,而不僅僅是響應者。這裏是我的ApplicationController,但不是全部包含您可能需要:

class Api::ApplicationController < ActionController::Metal 
    include ActionController::Helpers 
    include ActionController::UrlFor 

    include ActionController::Redirecting 
    include ActionController::Rendering   # enables rendering 
    include ActionController::ConditionalGet  # required for respond_to and respond_with 
    include ActionController::MimeResponds  # enables serving different content types like :xml or :json 

    include ActionController::Cookies    # enables cookies 
    include AbstractController::Callbacks   # callbacks for your authentication logic 
    include ActiveSupport::Rescuable    # enables resque_from 

    include Rails.application.routes.url_helpers 
end