Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom_payload for Rails 5 API's ActionController::API #227

Merged

Conversation

f3ndot
Copy link
Contributor

@f3ndot f3ndot commented Sep 19, 2017

Per the Rails 5 guide, if an app is using the API-only mode then they are to have ApplicationController inherit from ActionController::API instead of ActionController::Base. This breaks Lograge's custom payload feature.

My PR allows the developer to set the base class so that they can switch it to ActionController::API or something else should their app be very specialized.

@benlovell benlovell merged commit 1e61a3e into roidrage:master Sep 19, 2017
@benlovell
Copy link
Collaborator

Awesome. Thanks!

@benlovell
Copy link
Collaborator

I've just cut a release for 0.7.0.

@f3ndot
Copy link
Contributor Author

f3ndot commented Sep 19, 2017

@benlovell oh no! I've made a critical error.

By specifying the constant ActionController::API in the config, it causes the JSON APIs to not spit out their payload:

Rails.application.configure do
  config.lograge.base_controller_class = ActionController::API
end
$ curl http://localhost:3000/
%

The fix is to specify the string of the class then constantize it in Lograge. I'll make a PR posthaste!

Rails.application.configure do
  config.lograge.base_controller_class = 'ActionController::API'
end
$ curl http://localhost:3000/
{"foo": "bar"}%

@f3ndot f3ndot deleted the support-different-controller-bases branch September 19, 2017 14:15
@benlovell
Copy link
Collaborator

Gah, no problem. Thanks!

@minhdanh
Copy link

I'm using both ActionController:Base and ActionController:API for my rails app. So how can I configure the custom payload feature for both of these controllers?

@f3ndot
Copy link
Contributor Author

f3ndot commented Sep 26, 2017

I suspect the code would have to change so base_controller_class can optionally be an array and the setup method iterates the members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants