默认的“欢迎登机"在哪里?页面位于我的应用程序中? [英] Where is the default "Welcome Aboard" page located in my app?

查看:29
本文介绍了默认的“欢迎登机"在哪里?页面位于我的应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了我的应用程序目录,但找不到默认 rails Welcome Aboard 页面的 html 页面.我也无法在 routes.rb 中找到默认欢迎登机页面的路线.我的 rails 应用程序如何将 http://localhost:3000/ 路由到我的应用程序中不存在的页面?

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?

rails 服务器生成以下信息:

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.

推荐答案

从 Rails 4 开始,欢迎加入"页面不再位于 public/index.html 中.它 - 正如您已经发现的 - 位于其中一个 Rails gem 内.

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.

所以你已经自己回答了这个问题;欢迎登机"页面 - 在您的情况下 - 位于 /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

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. 创建控制器
  2. config/routes.rb 中添加根路由以路由到新创建的控制器.
  1. Create a controller
  2. Add a root route in config/routes.rb to route to that newly created controller.

至于对您的应用程序的请求如何最终到达 railties 内部的控制器,让我们深入研究一下:Inside Rails::Application::Finisher 我们发现:

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

当在开发模式下运行时,此块为您的应用程序添加了一些路由 - 其中之一是欢迎登机"操作的路由:get '/' =>"rails/welcome#index"

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"

这 - 就像任何其他初始化程序 - 在您启动应用程序服务器(运行 rails server 或您如何做)时完成.对于 Finisher,它的所有初始化器都在所有其他初始化器运行之后运行.

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.

注意路由是如何附加的,以便它们出现在路由集中的最后.结合 Rails 使用它找到的第一个匹配路由这一事实,确保只有在没有定义其他路由的情况下才会使用这些默认路由.

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.

这篇关于默认的“欢迎登机"在哪里?页面位于我的应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆