-
Notifications
You must be signed in to change notification settings - Fork 68
Using acts_as_api with Rails 5 API only version
Christian Bäuerlein edited this page Feb 6, 2017
·
5 revisions
When using Rails 5 in the API-only version, your application controller will inherit from ActionController::API
instead of the usual ActionController::Base
.
When you try to use the render helpers of acts_as_api within the controller, like render_for_api
, you might face an error like this:
NoMethodError (undefined method `render_for_api' for #<UsersController:0x007fecd4286fe0>
This is because the helper methods for rendering API responses rely on the ActionController::Base class being loaded. One solution is to include the helper methods in the controller manually. Just add this line to the top of your ApplicationController
:
include ActsAsApi::Rendering
And you should be able to use the helper methods again.
More information can be found in this ticket