Skip to content

Prevents ActionController::API from sending responses #285

@ened

Description

@ened

My API controller methods try to render JSON responses using jbuilder:

  def companies    
    render template: 'api/v1/users/companies', 
        format: :json,
        locals: { companies: current_user.companies }
  end

However, all responses are now empty.

As a fix, I removed the call to ActionController::Base.send :include and ActionController::API.send :include in https://github.com/ankane/ahoy/blob/master/lib/ahoy.rb#L119 and include the modules now manually:

class ApplicationController < ActionController::Base
  protect_from_forgery
  
  include Ahoy::Controller
class Api::ApiController < ActionController::API
  include Ahoy::Controller

I personally prefer this a lot, as it removes the magic and activates Ahoy explicitly.

Also see this PR for a similar discussion: rails/strong_parameters#144

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions