Search code examples
ruby-on-railsruby-on-rails-4webrick

Rails application not displaying index.html in development mode


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.


Solution

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