简体   繁体   English

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

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

I've took this post like basis but receive empty response every time. 我把这个帖子当作基础,但是每次都会收到空的响应。 What's wrong? 怎么了?

Basic controller: 基本控制器:

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

Controller: 控制器:

class Api::V1::UsersController < Api::V1::BaseController

  def index
    @user = User.find(params[:id])
  end

end

RABL template: RABL模板:

object @user

attributes :first_name

Try to include: 尝试包括:

include ActionController::ImplicitRender

I've been testing it with rails 4.0.4 and ruby 2.1.0 我一直在用Rails 4.0.4和ruby 2.1.0对其进行测试

This is minimal setup that works for me in Rails 4.1.8 : 这是在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

Feel free to add modules to your taste. 随意添加模块以符合您的口味。

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

相关问题 使用ActionController :: Metal设计验证 - Devise authentication with ActionController::Metal Rails 4 ActionController :: Metal与序列化器 - Rails 4 ActionController::Metal with Serializers ActionController :: Metal如何捕获所有异常以发送通知电子邮件? - ActionController::Metal How to catch all exceptions to send notification email? 如何制作new.json.rabl - How to make new.json.rabl 如何使RABL仅在对象中存在属性时才呈现它? - How can I make RABL render an attribute only if it exists in the object? Rspec停止工作 - ` <module:ActionController> &#39;:未初始化的常量ActionController :: Metal(NameError) - Rspec stopped working - `<module:ActionController>': uninitialized constant ActionController::Metal (NameError) Rails ActionController :: Metal实际上做了什么 - What actually does Rails ActionController::Metal 多个子模型和嵌套RABL —在HTML中工作 - Multiple Child Models and Nesting RABL — Works in HTML 如何使./script/generate创建RSpec而不是ActionController :: TestCases? - How to make ./script/generate create RSpecs instead of ActionController::TestCases? "ActionController::Metal 需要什么模块才能将状态代码传递给渲染?" - What module is needed with ActionController::Metal to be able to pass status code to render?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM