Routing
1. shallow包含了 :index , :create 和 :new action
resources :auctions, shallow: true do
resources :bids do
resources :comments
end
end
产生的route为
Prefix Verb URI Pattern Controller#Action
auction_bid_index GET /auctions/:auction_id/bid(.:format) bid#index
POST /auctions/:auction_id/bid(.:format) bid#create
new_auction_bid GET /auctions/:auction_id/bid/new(.:format) bid#new
edit_bid GET /bid/:id/edit(.:format) bid#edit
bid GET /bid/:id(.:format) bid#show
PATCH /bid/:id(.:format) bid#update
PUT /bid/:id(.:format) bid#update
DELETE /bid/:id(.:format) bid#destroy
2. concern减少代码重复
3. member
retract_auction GET
/auctions/:id/retract(.:format)
auctions#retract
resources :auctions do
resources :bids do
member do
get :retract
end
end
end
terminate_auctions GET|POST
/auctions/terminate(.:format)
auctions#terminate
resources :auctions do
match :terminate, via: [:get, :post], on: :collection
end
5. custom action name
resources :projects, path_names: { new: 'nuevo', edit: 'cambiar' }
GET
/projects/nuevo(.:format) projects#new
GET
/projects/:id/cambiar(.:format) projects#edit