问题描述
我有很多麻烦让我可以授权我在下面的新路由设置:
I having quite a bit of troubling getting cancan to authorize my new routes setup below:
namespace :api do
namespace :v1 do
resources :users do
resources :user_songs
resources :friendships
resources :plays
resources :likes
resources :songs
我已经按照此处发布的内容进行了操作并通过Likes控制器对其进行了测试,方法如下:
I have followed what was posted here https://github.com/ryanb/cancan/wiki/Nested-Resources and tested it with the likes controller by putting this above:
class Api::V1::LikesController < Api::V1::BaseController
load_and_authorize_resource :user
load_and_authorize_resource :like, :through => :user
使用罐子:access,:all inabilities.rb可以正常工作,但我尝试过的其他方法例如,
Using a can :access, :all in ability.rb works but anything else I have tried to limit is has not for example:
can :access, :likes
can :access, Like
can :access, :users
can :access, User
can :access, [:"users/likes", :users_likes]
我不太确定这是否归因于名称空间路由。
I am not too sure if the blame is because of the namespace routes or not. Any guidance would be extremely appreciated!
推荐答案
找出答案:毕竟是名称空间,只需要一个
Found out the answer: It was the namespace after all, it just needed a
can:access, api / v1 / likes
这篇关于使用CanCan授权命名空间和嵌套控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!