ruby - Rails DESTROY action on nested resource without ID -


i have following resource set in routes.rb file:

namespace :api, path: '/', defaults: { format: 'json' }, constraints: { subdomain: 'api' }   namespace :v1     resources :yums       resources :likes,  only: [:create, :destroy, :index]         match '/', to: 'likes#destroy', via: 'delete'       end     end   end end 

i wrote spec test requests:

describe "like api requests"   before (:each)      host! 'api.example.com'      @user = factorygirl.create(:user)     @other_user = factorygirl.create(:user)     @yum = factorygirl.create(:yum, user: @other_user)   end    describe "liking yum"     "should increase yum's count"       expect         post "/v1/yums/#{@yum.id}/likes", { authorization: token_header(@user.auth_token) }       end.to change(@yum.reload.likes, :count).by(1)     end   end    describe "unliking yum"     "should increase yum's count"       expect         delete "/v1/yums/#{@yum.id}/likes", { authorization: token_header(@user.auth_token) }       end.to change(@yum.reload.likes, :count).by(-1)     end   end end 

i want likes controller not require id destroy action since use methods on user model , unlike, scheme doesn't seem working, doing wrong?

try add route in routes.rb :

match "v1/yums/:yum_id/likes", to: "likes#destroy", via: "delete", defaults: { id: nil } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -