Mini John
Mini John

Reputation: 7941

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

load_and_authorize_resource

My Controller action's where written with the current_user method e.g.:

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.

How do i get this working properly ?

Upvotes: 0

Views: 230

Answers (1)

kobaltz
kobaltz

Reputation: 7070

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

Upvotes: 2

Related Questions