0

I have actions called 'follow' and 'unfollow' in my controller.
Obviously, CanCan won't recognize those actions so that it shows access denied when those actions are executed.

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

I added this line to ability.rb then it works fine now.
But the problem is when the user is not logged in it shows error like this

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

I only enable those actions when user is logged in.
How can I? What should I add to ability.rb?

4

2 回答 2

1

看来您缺少逗号:

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

这里

于 2013-01-01T18:48:17.650 回答
1

假设你的控制器是用户控制器,你可以在你的能力.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
于 2013-01-01T18:51:29.657 回答