swellactually swellactually - 15 days ago 5x
Ruby Question

Render a view in Rails 5 API

I generated an API-only rails app with Rails 5 via

rails new <application-name> --api
. I've decided I want to include a view for testing some things and am having issues getting a view to load.

I created a users/index.html.erb file with some text and my controller is now simply
def index; end
but there is nothing appearing when I hit the /users URL. I also tried commenting out the
# config.api_only = true
in config/application.rb but that didn't affect anything. Any suggestions on how to proceed?


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).


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