Browse files

Make Default Index Page Dynamic

Rails is a dynamic framework that serves a static `index.html` by default. One of my first questions ever on IRC was solved by "delete your index.html". This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion and show people how to set the root on their project all at the same time.

I encounter this question any time I am helping someone new learn Rails, and it is advice repeated again and again from our comments in rails/rails to external tutorials. We can remove this extra step and show people how to use rails root in the routes by allowing the index to be dynamic. 

This makes it easier to understand how to replace the root if desired, or to modify the index once generated since all rails helper methods are available. Eventually we can refactor this page to use standard Rails helpers instead of pure static html.


  • Loading branch information...
schneems committed Sep 25, 2012
1 parent 5f15956 commit 0bd6fa270b405d0f35031603b6dfce89b8aea055
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Move `public/index.html` to a dynamic page `app/views/pages/index.html.erb`.
+ *Richard Schneeman*
* Engines with a dummy app include the rake tasks of dependencies in the app namespace.
Fix #8229
@@ -0,0 +1,7 @@
+class PagesController < ApplicationController
+ def index
+ render layout: false
+ end
@@ -2,8 +2,9 @@
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
- # You can have the root of your site routed with "root" just remember to delete public/index.html.
- # root to: 'welcome#index'
+ # You can have the root of your site routed with "root"
+ root to: 'pages#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
@@ -55,7 +55,7 @@ def test_assets
assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/
assert_file "app/assets/stylesheets/application.css"
assert_file "config/application.rb", /config\.assets\.enabled = true/
- assert_file "public/index.html", /url\("assets\/rails.png"\);/
+ assert_file "app/views/pages/index.html.erb", /url\("assets\/rails.png"\);/
def test_invalid_application_name_raises_an_error

0 comments on commit 0bd6fa2

Please sign in to comment.