Skip to content

Commit

Permalink
Make Default Index Page Dynamic
Browse files Browse the repository at this point in the history
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.

Screenshot:

![](http://f.cl.ly/items/38212K0w1P063u2I0g2E/Screen%20Shot%202012-09-25%20at%204.51.42%20PM.png)
  • Loading branch information
schneems committed Nov 28, 2012
1 parent 5f15956 commit 0bd6fa2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ## ## 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. * Engines with a dummy app include the rake tasks of dependencies in the app namespace.
Fix #8229 Fix #8229


Expand Down
@@ -0,0 +1,7 @@
class PagesController < ApplicationController

def index
render layout: false
end

end
Expand Up @@ -2,8 +2,9 @@
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes". # 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: # Example of regular route:
# get 'products/:id' => 'catalog#view' # get 'products/:id' => 'catalog#view'
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/app_generator_test.rb
Expand Up @@ -55,7 +55,7 @@ def test_assets
assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/ assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/
assert_file "app/assets/stylesheets/application.css" assert_file "app/assets/stylesheets/application.css"
assert_file "config/application.rb", /config\.assets\.enabled = true/ 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"\);/
end end


def test_invalid_application_name_raises_an_error def test_invalid_application_name_raises_an_error
Expand Down

0 comments on commit 0bd6fa2

Please sign in to comment.