Reputation: 5825
I am trying to do something incredibly simple in Rails 5.0.0.alpha: render an HTML file that is not in the public
directory.
My route is this:
get '/api/docs' => 'static#documentation'
And my StaticController
looks like this:
class StaticController < ApplicationController
def documentation
render 'api/documentation/index.html'
end
end
The index.html
file I want to render is located in app/views/api/documentation/index.html
.
Whenever I load /api/docs
in the browser, all I get is a 200 OK
response with a blank page, meaning nothing is rendered.
I have tried just about every variant of render
:
render 'app/views/api/documentation/index.html'
render 'views/api/documentation/index.html'
render 'api/documentation/index.html'
render '/documentation/index.html'
render 'app/views/api/documentation/index'
render 'views/api/documentation/index'
render 'api/documentation/index'
render '/documentation/index'
render file: 'app/views/api/documentation/index'
render file: 'views/api/documentation/index'
render file: 'api/documentation/index'
render file: '/documentation/index'
etc. What am I missing?
Edit: Server output:
Started GET "/api/docs" for 198.167.XXX.XX at 2015-11-16 02:07:48 +0000
Processing by StaticController#documentation as HTML
Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
Upvotes: 0
Views: 4673
Reputation: 2033
For anyone else having similar problems as OP. If you're using an api_only rails application, make sure your controller inherits from ActionController::Base
instead of ActionController::API
Upvotes: 2
Reputation: 1580
I think it's because of main application template. you can fix in 2 way,
1. Check if the <%= yield %>
tag is in application.html.erb
Or, disable it using
layout false
in your StaticController
Upvotes: 0