rails里routes配置文件里的resources和resource的区别

抄自

In essence, routing resources is when resources gives action abilities to a controller.

http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use

If a pluralized resources is used as a way to handle generic requests on any item, then a singular resource is a way to work on the current item at hand.

So in other words, if I have a collection of Apples, to retrieve a specific apple, I'd have to tell the router "Apples" what apple to retrieve by sending the ID of the apple. If I already have one Apple, then an ID is not needed.

Notice the differences between the two by looking at what actions (or routes) they have:

  • resources: Index, new, create, show, edit, update, destroy
  • resource: new, create, show, edit, update, destroy

In your example:

  1. The controller "geocoder" is a singular resource that you can use to edit, create, update, etc.
  2. The controller "posts", is a plural resource that will handle incoming generic posts that you can index, edit, create.. etc

简单的说,resources比resource多了个index方法,针对具体业务的时候,resources适用于复数资源,resource用于单数资源

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值