Difference between member and collection of rails routes.rb

Differences between members and collections in routes.rb

I will describe the difference between member and collection when setting the routing in routes.rb of rails.

For menber

routes.rb


resources :buy_additional_actions, only: %i[] do
   member do
      get 'index' => 'buy_additional_actions#index'

In the case of menber,: id is automatically added to the generated url.

buy_additional_action GET /buy_additional_actions/:id/index(.:format) buy_additional_actions#index

For collection

routes.rb


resources :buy_additional_actions, only: %i[] do
   collection do
      get 'index' => 'buy_additional_actions#index'

In the case of collection,: id is not added to url.

buy_additional_actions GET /buy_additional_actions/index(.:format) buy_additional_actions#index

Recommended Posts

Difference between member and collection of rails routes.rb
Rails: Difference between resources and resources
[Rails] Difference between find and find_by
[rails] Difference between redirect_to and render
[Member and collection]
Difference between isEmpty and isBlank of StringUtils
Difference between addPanel and presentModally of FloatingPanel
[Rails] Difference between redirect_to and render [Beginner]
[Rails] Difference in behavior between delegate and has_many-through in the case of one-to-one-to-many
[Rails / ActiveRecord] About the difference between create and create!
Difference between vh and%
[Rails] Difference between create method and new + save method
Difference between i ++ and ++ i
[Rails] I learned about the difference between resources and resources
[Java] Difference between static final and final in member variables
[Rails] What is the difference between redirect and render?
[Rails] I investigated the difference between redirect_to and render.
Difference between product and variant
Difference between redirect_to and render
[Java] Difference between == and equals
Difference between puts and print
Difference between redirect_to and render
Difference between CUI and GUI
Difference between variables and instance variables
Difference between mockito-core and mockito-all
Difference between class and instance
Difference between bundle and bundle install
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
[Docker-compose] Difference between env_file and environment. Priority of environment variable application
[Rails] What is the difference between bundle install and bundle update?
[Ruby] About the difference between 2 dots and 3 dots of range object.
[Java] Difference between assignment of basic type variable and assignment of reference type variable
[Java] Difference between Stack Overflow Error and Out Of Memory Error
[Ruby] Difference between get and post
Difference between instance method and class method
Difference between render method and redirect_to
Difference between interface and abstract class
Difference between == operator and equals method
[Terminal] Difference between irb and pry
JavaServlet: Difference between executeQuery and executeUpdate
Difference between == operator and eqals method
Rough difference between RSpec and minitest
Understand the difference between each_with_index and each.with_index
Difference between instance variable and class variable
[JAVA] Difference between abstract and interface
Difference between Thymeleaf @RestController and @Controller
Difference between Stream map and flatMap
[Rails] Differences and usage of each_with_index and each.with_index
[Java] Difference between array and ArrayList
Difference between primitive type and reference type
Difference between string.getByte () and Hex.decodeHex (string.toCharaArray ())
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
[Android] Difference between finish (); and return;