简体   繁体   中英

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:

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

This is minimal setup that works for me in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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