2010-06-15 1 views
0

매우 한정적이고 제한된 목적을 가진 Rails 3 컨트롤러를 사용하고 있습니다. 필요한 것은 respond_to : json입니다.Rails 3에서 ActionController :: Metal에 Responder를 포함하려면 어떻게해야합니까?

이 스크린 캐스트는 내 컨트롤러가 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