Chapter 3 - REST, Resources, and Rails Flashcards
CRUD
Create, Read, Update, Delete is the classic summary of the spectrum of database operations.
resources
If you put
resources :auctions
into your config/ routes.rb file, you will have created four named routes, which, in a manner to be described in this chapter, connect to seven controller actions. And those actions have nice CRUD-like names, as you will see.
How to specify the request method when you generate a URL.
- The default request method is GET.
- In a form_tag or form_for call, the POST method will be used automatically.
- When you need to (which is going to be mostly with PATCH and DELETE operations), you can specify a request method along with the URL generated by the named route.
Limiting Routes Generated
resources :clients, except: [: index]
resources :clients, only: [: new, :create]
Limiting Routes Generated
resources :clients, except: [: index]
resources :clients, only: [: new, :create]
Nested Resources
resources :auctions do
resources :bids
end
link_to “See all bids”, auction_bids_path( auction)
Nested singular routes
For the singular routes (show, edit, destroy), you need at least two arguments:
link_to “Delete this bid”, auction_bid_path( auction, bid), method: :delete
Nested singular routes
For the singular routes (show, edit, destroy), you need at least two arguments:
2 different ways:
link_to “Delete this bid”, auction_bid_path( auction, bid), method: :delete
link_to “Delete this bid”, auction_bid_path( auction, bid), method: :delete
Nested singular routes
For the singular routes (show, edit, destroy), you need at least two arguments:
2 different ways:
link_to “Delete this bid”, auction_bid_path( auction, bid), method: :delete
link_to “Delete this bid”, auction_bid_path( auction, bid), method: :delete