Where is the default “Welcome Aboard” page located in my app?

后端 未结 1 536
借酒劲吻你
借酒劲吻你 2020-12-05 06:23

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 i

相关标签:
1条回答
  • 2020-12-05 06:44

    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.

    0 讨论(0)
提交回复
热议问题