Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 580
swellactually Avatar asked Oct 05 '16 22:10

swellactually


1 Answers

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
like image 100
RoM4iK Avatar answered Oct 10 '22 21:10

RoM4iK