简体   繁体   English

使用Controller中的current_user进行Cancan

[英]Cancan with current_user in Controller

I set up my Abilities, and on top of my Controller i have the authorize resource from Can Can 我设置了我的能力,在我的控制器之上我有Can Can的授权资源

load_and_authorize_resource

My Controller action's where written with the current_user method eg: 我的Controller动作是用current_user方法编写的,例如:

def new
  @question = current_user.questions.new
end

def edit
  @question = current_user.questions.find(params[:id])
end

With cancan this seems not to be working. 使用cancan,这似乎不起作用。

How do i get this working properly ? 我如何正常工作?

Based on your comments, this would be the expected behavior. 根据您的意见,这将是预期的行为。

Try modifying your edit action to 尝试将修改操作修改为

def edit
  if current_user.role_id == 4
    @question = Question.find(params[:id])
  else
    @question = current_user.questions.find(params[:id])
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM