【发布时间】:2016-08-22 09:13:32
【问题描述】:
我知道member 和collection 与resources 不同。
但是resource 怎么样?你用member 和collection 代替resource?。
我找到了
resource :foo do
patch :confirm
end
和
resource :foo do
member do
patch :confirm
end
end
和
resource :foo do
collection do
patch :confirm
end
end
都是一样的。
路线 => /foo/confirm(.:format)
方法 => 补丁
动作 => FoosController#confirm
名称 => confirm_foo
没有resource block的文档,只有resources block的文档。
Rails Routing from the Outside In — Ruby on Rails Guides
resource 不使用member 或collection 是收集方式吗?
member 或 collection 或不使用这些,哪个是最佳做法?
【问题讨论】:
-
resource方法is well documented仔细阅读。 -
是的。但不说成员和集合。
-
我不清楚你在问什么。 是正确的方式? 哪种方式?您可以使用您想要的,这完全取决于您的应用程序逻辑,
confirm用于member或collection的操作是什么?member会员,collection收藏。 -
我不会为
Singular Resources添加自定义路由。有很多方法。还有patch 'confirm', to: : confirm, controller: 'foos'。我想知道如何使用resource block。仅记录了resources block。 -
member和collectionforresources是不同的。但我认为resource的行为相同。
标签: ruby-on-rails