Sha256: 761f56d2e5627775904c8238d906e4d732beaae06c5b14e03d389c3c32e5e724

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module Draper
  module Compatibility
    # Draper expects your `ApplicationController` to include `ActionView::Rendering`. The
    # `ApplicationController` generated by Rails 5 API-only applications (created with
    # `rails new --api`) don't by default. However, including `ActionView::Rendering` in
    # `ApplicatonController` breaks `render :json` due to `render_to_body` being overridden.
    #
    # This compatibility patch fixes the issue by restoring the original `render_to_body`
    # method after including `ActionView::Rendering`. Ultimately, including `ActionView::Rendering`
    # in an ActionController::API may not be supported functionality by Rails (see Rails issue
    # for more detail: https://github.com/rails/rails/issues/27211). This hack is meant to be a
    # temporary solution until we can find a way to not rely on the controller layer.
    module ApiOnly
      extend ActiveSupport::Concern

      included do
        alias :previous_render_to_body :render_to_body
        include ActionView::Rendering
        alias :render_to_body :previous_render_to_body
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
draper-4.0.4 lib/draper/compatibility/api_only.rb
draper-4.0.3 lib/draper/compatibility/api_only.rb
draper-4.0.2 lib/draper/compatibility/api_only.rb
draper-4.0.1 lib/draper/compatibility/api_only.rb
draper-3.1.0 lib/draper/compatibility/api_only.rb
draper-3.0.1 lib/draper/compatibility/api_only.rb
draper-3.0.0 lib/draper/compatibility/api_only.rb