58

I scoured my app's directories, and I can't find the html page for the default rails Welcome Aboard page. I also cannot find a route for the default Welcome Aboard page in routes.rb. How does my rails app route http://localhost:3000/ to a non-existent page in my app?

The rails server produces this information:

Started GET "/" for 127.0.0.1 at 2013-07-31 02:00:13 -0600
Processing by Rails::WelcomeController#index as HTML
  Rendered /Users/7stud/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/templates/rails/welcome/index.html.erb (0.1ms)
Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.0ms)

So it looks to me like there is a controller buried in a gem somewhere that handles the request.

1
  • You can check if everythings alright by visiting the robots.txt Mar 5, 2015 at 22:07

1 Answer 1

75

Since Rails 4, the "Welcome aboard" page is no longer located in public/index.html. It is - as you've already detected - located inside one of the Rails gems.

So you already answered the question yourself; the "Welcome aboard" page is - in your case - located at /Users/7stud/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/templates/rails/welcome/index.html.erb

To get rid of it, following the instructions on the page. Basically they are:

  1. Create a controller
  2. Add a root route in config/routes.rb to route to that newly created controller.

As for how the request to your application ends up at a controller inside railties, let's dig into the gem: Inside Rails::Application::Finisher we find this:

initializer :add_builtin_route do |app|
  if Rails.env.development?
    app.routes.append do
      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

This block adds a few routes to your application when running in development mode - one of those is the route to the "Welcome aboard" action: get '/' => "rails/welcome#index"

This - like any other initializer - is done when your start your application server (running rails server or however you do it). In the case of Finisher, all its initializer are run after all other initializers are run.

Note how the routes are appended so that they are appear last in the Routeset. This, combined with the fact that Rails uses the first matching route it finds, ensures those default routes will only get used if no other route is defined.

5
  • 3
    You are too fast for me :) Jul 31, 2013 at 8:20
  • One lingering doubt: how does my app route http://localhost:3000/ to the controller in the gem? Does rails automatically route to the controller in that gem if the route '/' doesn't match anything in routes.rb?
    – 7stud
    Jul 31, 2013 at 8:30
  • 1
    Updated my answer, but the short answer is "yes".
    – Jakob S
    Jul 31, 2013 at 9:08
  • I created a home controller and index.html along with this added this in routes as well. Still its loading the welcome page. any suggestions ?? please
    – Kiran
    Oct 28, 2017 at 5:01
  • Rails.application.routes.draw do get 'home/index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end This is the code in my route.erb
    – Kiran
    Oct 28, 2017 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.