You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we add gem 'draper' to our Gemfile in our Rails 5.0.x project, it breaks our ActionController::API requests by causing an empty string to be returned. I believe this is due to our use of the responders gem as well.
So, has_view_rendering? returns true due to the injection of ActionView::Rendering into the class hierarchy by Draper in the Draper::Compatability::ApiOnly module. This causes the default_render to be called and not the api_behavior which is what we need and see when we don't have the Draper gem in the Gemfile.
The ApiOnly module is run automatically upon gem load to "temporarily" add view_context support to ActionController::API. In the comments it explicitly calls this a "hack" and "temporary solution". If so, there should be a way for developers to opt out of this functionality.
It seems like a very bad practice to modify class hierarchies just by adding a gem. Is it possible to add a setting to opt out of this behavior - or better, make it opt-in.
PS. Other than this, love the gem.
The text was updated successfully, but these errors were encountered:
When we add
gem 'draper'
to our Gemfile in our Rails 5.0.x project, it breaks our ActionController::API requests by causing an empty string to be returned. I believe this is due to our use of theresponders
gem as well.We see the debugger hit the following:
So,
has_view_rendering?
returns true due to the injection of ActionView::Rendering into the class hierarchy by Draper in the Draper::Compatability::ApiOnly module. This causes thedefault_render
to be called and not theapi_behavior
which is what we need and see when we don't have the Draper gem in the Gemfile.The ApiOnly module is run automatically upon gem load to "temporarily" add view_context support to ActionController::API. In the comments it explicitly calls this a "hack" and "temporary solution". If so, there should be a way for developers to opt out of this functionality.
draper/lib/draper/compatibility/api_only.rb
Lines 1 to 23 in aaa06bd
It seems like a very bad practice to modify class hierarchies just by adding a gem. Is it possible to add a setting to opt out of this behavior - or better, make it opt-in.
PS. Other than this, love the gem.
The text was updated successfully, but these errors were encountered: