Render a view in Rails 5 API

You don't need to uncomment config.api_only = true for this purpose, just inherit your controller from ActionController::Base, or do it in your ApplicationController (default for common rails generation).

Code:

  1. For this controller only YourController < ActionController::Base
  2. For all apllication ApplicationController < ActionController::Base

this is from the ActionController::Metal docs https://apidock.com/rails/ActionController/Metal

it says:

ActionController::Metal by default provides no utilities for rendering >views, partials, or other responses aside from explicitly calling of >response_body=, content_type=, and status=. To add the render helpers >you’re used to having in a normal controller, you can do the following:

class HelloController < ActionController::Metal
 include AbstractController::Rendering
 include ActionView::Layouts
 append_view_path "#{Rails.root}/app/views"

  def index
   render "hello/index"
  end
end

So I've tried it myself and adding just by adding the two modules actually work just fine when using it for ActionController::API