0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

resourceとresourcesの違い on Rails

0
Posted at

resource と resourcesの違い

このサイト曰く、
resourceとresourcesの違い

「resourceメソッド」にはidが付与されていません。ということはつまり、リソースを絞り込めない(絞り込まない)状況で使用します。

その一方で「resourcesメソッド」はidが付与されています。そのため、複数あるリソースの中からidを用いて特定のリソースを絞り込むことができます。

まとめると、複数存在するリソース(商品やユーザーなど)では「resources」を使用し、1つしか存在しないリソースには「resouece」を使用します。

わかりやすい。

あと、resourceでは一つのリソースしかない(resourcesみたいに複数のユーザがいたりしない)のでindexアクションが必要ない。だからresourceではindexアクションのルートは生成されない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?