gpt4 book ai didi

ruby-on-rails - root 应该位于 routes.rb 文件中的什么位置?

转载 作者:太空宇宙 更新时间:2023-11-03 17:43:49 24 4
gpt4 key购买 nike

可能是一些微不足道的事情,但我想知道根关键字及其 Controller 操作应该放在 routes.rb 文件中的什么地方。

Rails.application.routes.draw do
get 'welcome/index'

root 'welcome#index'
end

我看过几个教程,大多数教程似乎都在底部。这是有原因的吗?

最佳答案

根据Rails routing guide

You should put the root route at the top of the file, because it is the most popular route and should be matched first.

部分推理是

Rails routes are matched in the order they are specified...

因此,您希望最常用的路由位于文件的早期/高位,这样您就不必遍历并浪费时间检查大量不常见或非常罕见的路由。

关于ruby-on-rails - root 应该位于 routes.rb 文件中的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45788633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com