From baea5d69be52def2a81c31cd119f8dfcd2aa087b Mon Sep 17 00:00:00 2001 From: schneems Date: Wed, 5 Dec 2012 13:02:51 -0600 Subject: Use Rails to Render Default Index Page This is an alternative implementation to #7771 thanks to the advice of @spastorino Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. 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. This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required. In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated. The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one). cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik ATP Railties and Actionpack. --- railties/lib/rails/application/finisher.rb | 1 + railties/lib/rails/generators/app_base.rb | 3 - .../rails/generators/rails/app/app_generator.rb | 5 - .../rails/app/templates/config/routes.rb | 2 +- .../rails/app/templates/public/index.html | 241 --------------------- .../rails/templates/rails/welcome/index.html.erb | 240 ++++++++++++++++++++ railties/lib/rails/welcome_controller.rb | 7 + 7 files changed, 249 insertions(+), 250 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/app/templates/public/index.html create mode 100644 railties/lib/rails/templates/rails/welcome/index.html.erb create mode 100644 railties/lib/rails/welcome_controller.rb (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 2d87b8594a..09902ad597 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -25,6 +25,7 @@ module Rails get '/rails/info/properties' => "rails/info#properties" get '/rails/info/routes' => "rails/info#routes" get '/rails/info' => "rails/info#index" + get '/' => "rails/welcome#index" end end end diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index de3127f43e..77db881b65 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -52,9 +52,6 @@ module Rails class_option :skip_javascript, type: :boolean, aliases: '-J', default: false, desc: 'Skip JavaScript files' - class_option :skip_index_html, type: :boolean, aliases: '-I', default: false, - desc: 'Skip public/index.html and app/assets/images/rails.png files' - class_option :dev, type: :boolean, default: false, desc: "Setup the #{name} with Gemfile pointing to your Rails checkout" diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 18637451ac..c98f021cfe 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -97,11 +97,6 @@ module Rails def public_directory directory "public", "public", recursive: false - if options[:skip_index_html] - remove_file "public/index.html" - remove_file 'app/assets/images/rails.png' - keep_file 'app/assets/images' - end end def script diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb index 631543c705..22a6aeb5fe 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb @@ -2,7 +2,7 @@ # 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. + # You can have the root of your site routed with "root" # root to: 'welcome#index' # Example of regular route: diff --git a/railties/lib/rails/generators/rails/app/templates/public/index.html b/railties/lib/rails/generators/rails/app/templates/public/index.html deleted file mode 100644 index dd09a96de9..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/public/index.html +++ /dev/null @@ -1,241 +0,0 @@ - - - - Ruby on Rails: Welcome aboard - - - - -
- - -
- - - - -
-

Getting started

-

Here’s how to get rolling:

- -
    -
  1. -

    Use rails generate to create your models and controllers

    -

    To see all available options, run it without parameters.

    -
  2. - -
  3. -

    Set up a default route and remove public/index.html

    -

    Routes are set up in config/routes.rb.

    -
  4. - -
  5. -

    Create your database

    -

    Run rake db:create to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

    -
  6. -
-
-
- - -
- - diff --git a/railties/lib/rails/templates/rails/welcome/index.html.erb b/railties/lib/rails/templates/rails/welcome/index.html.erb new file mode 100644 index 0000000000..6a1754d81e --- /dev/null +++ b/railties/lib/rails/templates/rails/welcome/index.html.erb @@ -0,0 +1,240 @@ + + + + Ruby on Rails: Welcome aboard + + + + +
+ + +
+ + + + +
+

Getting started

+

Here’s how to get rolling:

+ +
    +
  1. +

    Use rails generate to create your models and controllers

    +

    To see all available options, run it without parameters.

    +
  2. + +
  3. +

    Routes are set up in config/routes.rb.

    +
  4. + +
  5. +

    Create your database

    +

    Run rake db:create to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

    +
  6. +
+
+
+ + +
+ + diff --git a/railties/lib/rails/welcome_controller.rb b/railties/lib/rails/welcome_controller.rb new file mode 100644 index 0000000000..45b764fa6b --- /dev/null +++ b/railties/lib/rails/welcome_controller.rb @@ -0,0 +1,7 @@ +class Rails::WelcomeController < ActionController::Base # :nodoc: + self.view_paths = File.expand_path('../templates', __FILE__) + layout nil + + def index + end +end -- cgit v1.2.3