0

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?

Community
  • 1
  • 1
pasine
  • 11,311
  • 10
  • 49
  • 81

2 Answers2

2

Note that in the normal case ActiveScaffold config is done in the class not the instance so there is no current_user set because there is no request yet.

Michael Latta
  • 47
  • 1
  • 4
1

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

Jed Schneider
  • 14,085
  • 4
  • 35
  • 46