Chris Cirefice
Chris Cirefice

Reputation: 5825

Rails render HTML file outside of 'public'

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:

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

Answers (2)

Gideon Rosenthal
Gideon Rosenthal

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

Padhu
Padhu

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

Related Questions