繁体   English   中英

make Rabl如何与ActionController :: Metal一起使用

[英]How make Rabl works with ActionController::Metal

我把这个帖子当作基础,但是每次都会收到空的响应。 怎么了?

基本控制器:

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

RABL模板:

object @user

attributes :first_name

尝试包括:

include ActionController::ImplicitRender

我一直在用Rails 4.0.4和ruby 2.1.0对其进行测试

这是在Rails 4.1.8中对我有用的最小设置:

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

随意添加模块以符合您的口味。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM