-
Notifications
You must be signed in to change notification settings - Fork 526
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
Add support for Rails 5 API-only applications #793
Conversation
Does anybody have an opinion on this? @syguer? |
@codebycliff |
@codebycliff Thanks for working on this! Sorry I haven't been able to respond sooner. I do wonder though, is it possible for Draper to internally use a subclass of ApplicationController by default, so that it's not modifying ApplicationController? Also, would that fix the issue regarding default_controller ||= Class.new(ApplicationController) do I haven't looked at the code in a while, so I'm just brainstorming here. Maybe this won't work for reasons I've forgotten. |
@codebycliff @syguer To make a long story short, this fix means that I cannot - in a Rails 5 app in API mode - extend from That logic might be flawed, but I am unsure how to fix it there. Since you seem to be intent on removing the "reliance on the controller layer" (as mentioned in the diff), I might be able to help to get this effort started. Is there any place where the plan of attack for that issue is laid out? |
@jpettettphaxio I agree that it makes more sense to use a subclass and not directly modifying @franzliedke I would love to remove the reliance on the controller layer and would appreciate any help you could provide. However, there is no plan of attack at the moment unfortunately. If you have ideas or want to brainstorm solutions, I am all ears. Removing the reliance on the controller would solve your problem above. Without doing that, I am unsure of how much Draper should support |
@codebycliff Thanks for getting back! Can you quickly explain what "reliance on the controller layer" currently means? From my quick deep dive, it seems to be about gathering the view and route helpers from the controller, so that they are available in the decorators. Is that right? |
Yes. There are two files in particular where most of this is happening. In Draper, it's using |
When we installed Draper to provide decorators to our mailers, we inadvertently broke the OAuth controller. This is likely due to the following issues in Draper, which do not appear to have been fully solved in Draper 3.0.1. Because this is the only place we use ActionView outside of Mailers, for now we will just render the content from the controller. In the future, if we need more view functionality, we'll use cells. See: rails/rails#27211 drapergem/draper#793 Fixes #1631
When we installed Draper to provide decorators to our mailers, we inadvertently broke the OAuth controller. This is likely due to the following issues in Draper, which do not appear to have been fully solved in Draper 3.0.1. Because this is the only place we use ActionView outside of Mailers, for now we will just render the content from the controller. In the future, if we need more view functionality, we'll use cells. See: rails/rails#27211 drapergem/draper#793 Fixes #1631
When we installed Draper to provide decorators to our mailers, we inadvertently broke the OAuth controller. This is likely due to the following issues in Draper, which do not appear to have been fully solved in Draper 3.0.1. Because this is the only place we use ActionView outside of Mailers, for now we will just render the content from the controller. In the future, if we need more view functionality, we'll use cells. See: rails/rails#27211 drapergem/draper#793 Fixes #1631
Description
Draper expects your
ApplicationController
to includeActionView::Rendering
. TheApplicationController
generated by Rails 5 API-only applications (created withrails new --api
) doesn't by default. However, includingActionView::Rendering
inApplicatonController
breaksrender :json
due torender_to_body
being overridden.This compatibility patch fixes the issue by restoring the original
render_to_body
method after including
ActionView::Rendering
.Originally, I was going to provide documentation in the README on how to apply this patch. However, I ended up deciding to build it in. That way Draper works out of the box for api only applications at the expense of including
ActionView::Rendering
inApplicationController
.Ultimately, including
ActionView::Rendering
in anActionController::API
may not be supported functionality by Rails (see Rails issue for more detail: rails/rails#27211). This hack is meant to be a temporary solution until we can find a way to not rely on the controller layer.Testing
rails new api_only --api
gem 'draper', github: 'drapergem/draper', branch: 'feature/rails-5-api-only-support'
rails c
. This should no longer throw an exception.rails g scaffold Post title description
render :json
.To-Dos
References