新手问题 [已解] 一个关于 Rails 的路由问题,求解

perish · December 26, 2014 · Last by perish replied at December 27, 2014 · 1813 hits

如上两张图

为什么当 infos 或者 aaas 的时候,后面没有_index, 而 aaa 或者 news 的时候后面会加个_index 呢?

1 Floor has deleted
2 Floor has deleted

#1 楼 @ken 没明白,能讲清楚一些嘛?谢谢

@perish 你 aaa 的命名有问题啊,说你是单路由,你还有 index,说你是复数路由你的复数呢???看看 resetful 吧! http://guides.ruby-china.org/routing.html#单数资源

Rails 中的单复数比较敏感。这也是一种“convention over configuration”吧。

#4 楼 @colorfulberry 恩恩,但是那个 news 是个复数吧,为什么还有_index 呢?难道是因为有 new 这个关键词?

#5 楼 @zhangsm 是的,那个 news,怎么解呢?

#7 楼 @perish news 用作新闻的时候单复数同名,或者说没有单数。所以复数 helper 加 index 和单数 helper 区分开。如果 Rails 无法推测资源名的复数形式也会加上 index。

#8 楼 @Rei 这样就明白了,谢谢

perish closed this topic. 14 Jul 16:49
You need to Sign in before reply, if you don't have an account, please Sign up first.