Search code examples
ruby-on-railspermissionscancanscaffold

undefined method current_user: Cancan and Active Scaffold


I'm trying to add an action link to an active scaffold controller using

if current_user.can? :update, Post
  config.action_links.add 'export', :label => 'Export', :page => true
end

but whatever controller I try to use, I always get undefined method current_user
So, how can I check if the logged user can/cannot do something?
I've even tried with

def ability
  @ability ||= Ability.new(self)
end
delegate :can?, :cannot?, :to => :ability

as suggested here, but without success.
What's wrong with this?


Solution

  • current_user is a typically defined method, but it is one that you must add. it is not supplied by rails. So, you need a current_user method in your ApplicationController. There are tons of examples but I would look at the authlogic example app on github