[RUBY] [Member and collection]

What are members and collections?

Currently, I am creating an app like the photo posting version of Twitter, but I will output about the members and collection that came out when implementing the post search function during the creation and the difference between them.

members and collections can be used when configuring routing, and the generated URL and the controller to be executed can be customized as desired.

The difference is that collection does not have: id in the routing and member does.

search1.png

If you put the collection in the nest of the tweets controller as shown in the image above, It will be the routing of the following image.

search2.png

Even if I look at the URI, the id is not included.

On the other hand, when described by member

search3.png

The routing in this case looks like the image below.

search4.png

As you can see, the routing contains the id.

In the case of the photo posting app created this time, I used collection because I just want to display a list as search results and do not need a detailed page for each id.

Recommended Posts

[Member and collection]
Difference between member and collection of rails routes.rb
== and equals
☾ Java / Collection
Java9 collection
[Java] Collection and StringBuilder operation method comparison
[Java] Contents of Collection interface and List interface
Kantai Collection Java # 1 Classes and Objects [For Beginners]