Ruby:为什么用#而不是/?
Ruby: why use # not /?
在下面,#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 '/'
的 shorthand。所以你没有指定请求路径。
在最后两条规则中,destination可以省略,因为Rails会自动计算。
我建议你阅读官方Rails routing guide。它解释了所有这些事情。
在下面,#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 '/'
的 shorthand。所以你没有指定请求路径。
在最后两条规则中,destination可以省略,因为Rails会自动计算。
我建议你阅读官方Rails routing guide。它解释了所有这些事情。