首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >make Rabl如何使用ActionController::Metal

make Rabl如何使用ActionController::Metal
EN

Stack Overflow用户
提问于 2014-07-21 04:39:21
回答 2查看 249关注 0票数 0

我使用了类似于basis的post,但每次都收到空响应。怎么了?

基本控制器:

代码语言:javascript
复制
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

控制器:

代码语言:javascript
复制
class Api::V1::UsersController < Api::V1::BaseController

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

end

RABL模板:

代码语言:javascript
复制
object @user

attributes :first_name
EN

回答 2

Stack Overflow用户

发布于 2014-08-12 16:38:48

尝试包含以下内容:

代码语言:javascript
复制
include ActionController::ImplicitRender

我已经使用rails 4.0.4和ruby 2.1.0对其进行了测试

票数 0
EN

Stack Overflow用户

发布于 2014-12-25 08:21:25

这是适用于我在Rails 4.1.8中的最小设置

代码语言:javascript
复制
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

您可以根据自己的喜好添加模块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24854701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档