I have placed an index.html
file in the public
directory of my Rails 4 application but it still shows this deleted file as rails welcome page. I am using Webrick in development mode. I have another app almost identical in setup which works fine.

- 1,453
- 2
- 18
- 37

- 1,199
- 19
- 82
- 151
-
make sure that you dont have a typo or a extra space in your file name or path. that is most likely the problem – MZaragoza Sep 08 '13 at 13:57
-
I have checked that carefully - doesn't seem to be the problem. – markhorrocks Sep 08 '13 at 14:01
-
have you restart your server? – rails_id Sep 08 '13 at 14:21
-
Yes, that in't the problem. – markhorrocks Sep 09 '13 at 00:11
3 Answers
As written above, Rails 4 has removed the default index.html page in the /public folder. If you want to achieve the functionality anyway, you have to render the page manually. Just create a controller, and render the index page in your chosen controller action like this:
def index
render :file => 'public/index.html' and return
end
EDIT:
If you want to serve the files without using the Rails stack, you have to configure your Web server (Apache/Nginx/whatever) to do so. Configurations for Nginx and Apache.
Additionally, you have to disable Rails' static file rendering in your configuration by setting serve_static_assets
to false:
config.serve_static_assets configures Rails itself to serve static assets. Defaults
to true, but in the production environment is turned off as the server software (e.g.
Nginx or Apache) used to run the application should serve static assets instead.
Unlike the default setting set this to true when running (absolutely not recommended!)
or testing your app in production mode using WEBrick. Otherwise you won´t be able use
page caching and requests for files that exist regularly under the public directory
will anyway hit your Rails app.
So, if you want to use this in development mode, set config.serve_static_assets
to false in environments/development.rb
.

- 1
- 1

- 2,053
- 1
- 16
- 28
-
So, are you saying it's impossible to have a domain point to an index page without rendering it from a rails app if there is a rails app associated with the domain? If I type mydomain.com/index.html into a browser, I get a no route matches error message. Presumably this would be the same for every static page? Am I missing something here? – markhorrocks Sep 11 '13 at 13:15
-
Looks like I didn't understand your question. Answer is now updated. – Lukas_Skywalker Sep 11 '13 at 13:56
Rails 4 uses dynamic index.html. Read on http://blog.remarkablelabs.com/2012/12/dynamic-index-html-rails-4-countdown-to-2013

- 11,910
- 11
- 38
- 53
-
This does not solve my problem as I want to display my index.html page. – markhorrocks Sep 08 '13 at 23:35
Press F5 in navigator, the index can be in the cache.

- 2,053
- 1
- 16
- 28

- 1,520
- 19
- 27