Authorization of Namespaced and nested controllers using CanCan

I have quite a few problems getting cancan to authorize my new route setup below:

namespace :api do namespace :v1 do resources :users do resources :user_songs resources :friendships resources :plays resources :likes resources :songs 

I followed what was posted here https://github.com/ryanb/cancan/wiki/Nested-Resources , and tested it using a similar controller, putting this above:

 class Api::V1::LikesController < Api::V1::BaseController load_and_authorize_resource :user load_and_authorize_resource :like, :through => :user 

Using can: access ,: all in the capability.rb function, but everything I tried to limit does not have, for example:

 can :access, :likes can :access, Like can :access, :users can :access, User can :access, [:"users/likes", :users_likes] 

I'm not sure if this is to blame for the namespace routes or not. Any guidance would be greatly appreciated!

+5
source share
1 answer

Found the answer: in the end, it was a namespace, he just needed

can :access, "api/v1/likes"

+5
source

Source: https://habr.com/ru/post/922686/


All Articles