jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
320 stars 63 forks source link

Wrap jsonapi methods in a helper module to avoid polluting the controller #43

Closed mdeutsch closed 7 years ago

mdeutsch commented 7 years ago

Rather than adding a bunch of jsonapi_* methods to the controller, add a single method that returns a helper object and define the methods in the helper. For example, jsonapi_pointers would become jsonapi.pointers.

I got this idea from the paper_trail gem: airblade/paper_trail#719. I've done it in our Rails application to customize jsonapi-rails for our use case. If it's of interest, I can put together a PR.

beauby commented 7 years ago

Hi Michael – avoiding pollution of ActionController::Base is definitely something I'm interested in (I introduced today an option to prevent the railtie to automatically mixin the JSONAPI::Rails::Controller module).

Please do issue a PR, as your solution strikes me as a good balance.

Cheers,

Lucas

On Tue, 25 Jul 2017 at 15:59, Michael Deutsch notifications@github.com wrote:

Rather than adding a bunch of jsonapi_* methods to the controller, add a single method that returns a helper object and define the methods in the helper. For example, jsonapi_pointers would become jsonapi.pointers.

I got this idea from the paper_trail gem: airblade/paper_trail#719 https://github.com/airblade/paper_trail/pull/719. I've done it in our Rails application to customize jsonapi-rails for our use case. If it's of interest, I can put together a PR.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jsonapi-rb/jsonapi-rails/issues/43, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHPYjhOEMLK4fH22feiokE3jUjD8zhiks5sRfTWgaJpZM4OimM8 .

-- Lucas Hosseini lucas.hosseini@gmail.com

beauby commented 7 years ago

Hi Michael – the direction jsonapi-rails is currently taking is that of overridable hooks in the controller. I'm going to close this issue for now, but feel free to reopen it should you think of a better pattern.

mdeutsch commented 7 years ago

No worries. Sorry for dropping the ball on this -- I went out on paternity leave earlier than expected and now that I'm back I've been focused on another project.

beauby commented 7 years ago

No worries – and congratulations!