Ruby on rails make Rabl如何使用ActionController::Metal
我采取了类似的方法,但每次都收到空的回复。怎么了 基本控制器:Ruby on rails make Rabl如何使用ActionController::Metal,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,rabl,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 4,Rabl,我采取了类似的方法,但每次都收到空的回复。怎么了 基本控制器: class Api::V1::BaseController < ActionController::Metal include AbstractController::Rendering include AbstractController::Callbacks include AbstractController::Helpers include ActionController::HttpAuthenti
class Api::V1::BaseController < ActionController::Metal
include AbstractController::Rendering
include AbstractController::Callbacks
include AbstractController::Helpers
include ActionController::HttpAuthentication::Token::ControllerMethods
include ActionController::Rendering
include ActionController::Renderers::All
include ActionController::MimeResponds
include ActionController::Instrumentation
append_view_path "#{Rails.root}/app/views"
respond_to :json
end
class Api::V1::UsersController < Api::V1::BaseController
def index
@user = User.find(params[:id])
end
end
尽量包括:
include ActionController::ImplicitRender
我一直在用rails 4.0.4和ruby 2.1.0对其进行测试,这是我在rails 4.1.8中的最低设置:
您可以随意添加模块 那么,您将哪些数据序列化为json?在哪里为RABL模板定义@settings变量?尝试改用controller@user中定义的。抱歉,示例中有一个输入错误。我在模板中使用@user
include ActionController::ImplicitRender
class Api::V1::BaseController < ActionController::Metal
include AbstractController::Rendering # Basic rendering
include ActionView::Rendering # Finds view using lookup_context and append_view_path
include ActionController::Rendering # Support respond_to and render formats
include ActionController::MimeResponds # MIME type for respond_to
include ActionController::ImplicitRender # Implicitly calls render so you don't
include ActionController::Instrumentation # Sets Content-Type header amongst others
append_view_path "#{Rails.root}/app/views" # Get views from here
end