Skip to content

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.

The suggested solution is to manually include the helper methods in the specific controller or to include it in ApplicationController if you need it in multiple controllers.

include ActsAsApi::Rendering

And you should be able to use the helper methods again.

More information can be found in this ticket