我搜索了应用程序的目录,但找不到默认的 Rails Welcome Aboard 页面的 html 页面。我也无法在routes.rb 中找到默认Welcome Aboard 页面的路线。我的 Rails 应用如何将 http://localhost:3000/
路由到应用中不存在的页面?
rails 服务器生成以下信息:
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)
所以在我看来,好像有一个 Controller 埋在 gem 中处理请求的地方。
最佳答案
自 Rails 4 起,“Welcome aboard”页面不再位于 public/index.html
中。正如您已经检测到的,它位于 Rails gem 之一内。
所以你自己已经回答了这个问题; “欢迎加入”页面 - 在您的情况下 - 位于 /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
要删除它,请按照页面上的说明进行操作。基本上它们是:
- 创建 Controller
- 在
config/routes.rb
中添加根路由以路由到新创建的 Controller 。
至于对应用程序的请求如何最终到达 Railties 内的 Controller ,让我们深入研究一下这个 gem :Inside Rails::Application::Finisher
我们发现这个:
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
此 block 在开发模式下运行时向您的应用程序添加了一些路由 - 其中之一是到“Welcome aboard”操作的路由:get '/' => "rails/welcome#index"
这 - 与任何其他初始化程序一样 - 在启动应用程序服务器时完成(运行 rails server
或无论如何执行)。对于Finisher
,它的所有初始化程序都会在所有其他初始化程序运行之后运行。
请注意如何附加路由,以便它们出现在路由集中的最后。这与 Rails 使用它找到的第一个匹配路由的事实相结合,确保只有在没有定义其他路由的情况下才会使用这些默认路由。
关于ruby-on-rails - 我的应用程序中的默认 "Welcome Aboard"页面位于何处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17964830/