2013-01-01 23 views
0

我在控制器中有“跟随”和“取消关注”的操作。
显然,CanCan将不会识别这些操作,以便在执行这些操作时显示拒绝访问。如何使用CanCan启用自定义操作?

alias_action :follow, :unfollow :to => :read 

我加入这行ability.rb那么它现在正常工作。
但问题是当它不记录用户显示错误这样

syntax error, unexpected ':', expecting keyword_end 
    alias_action :follow, :unfollow :to => :read 

当用户登录时,我只允许那些动作。
我哪有?我应该添加到ability.rb

回答

1

看来你错过了一个逗号:

alias_action :follow, :unfollow, :to => :read 

看到here

+0

哎呀,我很愚蠢的忘记了。谢谢:) – MKK

1

假设你的控制器是UsersController,你可以在你ability.rb外商投资企业做到这一点

def initialize(user) 
    user || = User.new 
    if user.roles.include?('tweeple') #Assuming the user with role tweeple can follow/ unfollow 
    can [:follow, :unfollow], User 
    end 
end 
相关问题