2017-05-12 53 views
0

friendships控制器所需起初只有两个动作,createdestroy,所以我加入config/routes.rb如下:如何添加自定义路线以有限的资源

resources :friendships, only: [:create, :destroy] 

然而,我不得不添加自定义drop允许用户放弃友谊请求的行动。 因为我只需要这三个动作,我不会不使用所有RESTful资源,我不知道是否可以编辑config/routes.rb如下:

resources :friendships, only: [:create, :destroy] do 
    member do 
    post :request, action: :drop 
    end 
end 

回答

1

是的,你可以;这样做会导致这样的路线:

  Prefix Verb URI Pattern      Controller#Action 
request_friendship POST /friendships/:id/request(.:format) friendships#drop 
     friendships POST /friendships(.:format)    friendships#create 
     friendship DELETE /friendships/:id(.:format)   friendships#destroy 
相关问题