Ruby on rails 鲁比:为什么要用#not/?
在以下内容中,使用Ruby on rails 鲁比:为什么要用#not/?,ruby-on-rails,url-routing,Ruby On Rails,Url Routing,在以下内容中,使用#home而不是/home的原因是什么?所有其他的都是/help,/about Rails.application.routes.draw do root 'static_pages#home' get 'static_pages/help' get 'static_pages/about' end 这完全等同于您提供的代码: Rails.application.routes.draw do get '/', to: 's
#home
而不是/home
的原因是什么?所有其他的都是/help
,/about
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
end
这完全等同于您提供的代码:
Rails.application.routes.draw do
get '/', to: 'static_pages#home'
get 'static_pages/help', to: 'static_pages#help'
get 'static_pages/about', to: 'static_pages#about'
end
哈希符号#
将路由目标字符串中的控制器和操作名称分开
在您的示例中,使用root
方法。它是get'/'
的缩写。所以您不指定请求路径
在最后两个规则中,可以省略destination,因为Rails会自动计算它
我建议你读一下官方的。它解释了所有这些事情。以上是以下教程的一部分:谢谢!!但是为什么不直接写:root'static_pages/home'我想这是因为Rails会感到困惑:您指定了请求路径还是控制器+操作字符串?谢谢!!!我用你上面修改过的解释得到了!!!非常感谢你!!!!不客气:)如果你喜欢这个答案,你能接受吗?