Ruby on rails 3 -未定义的局部变量或方法' current_user'对



我得到

undefined local variable or method `current_user` error for

是由我的视图

中的以下代码引起的
<% if can? :update, Project %>
  <span class="admin">
    <%= link_to 'Nieuw Project', new_project_path %>
  </span>
<% end %>

当我删除代码时,页面会正确呈现。

康康舞代码:

class Ability
  include CanCan::Ability
  def initialize(user)   
    user ||= User.new
    if user.admin?
      can :manage, Post
      can :manage, Project
      can :manage, Page
      can :manage, Comment
      can :manage, User
    else
      can :read, :all
      cannot :read, User      
      can :create, Comment      
    end
  end
end
用户模式:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :lockable and :timeoutable
  devise :invitable, :database_authenticatable, #:registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable
  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation
  def admin?
    self.id
  end
end

my app specs

    rails 3.0.3
  • 设计1.5.3
  • 设计邀请0.6.0
  • 康康舞1.6.4

也许你正沉迷于这个关于cancan和design的小细节。https://github.com/ryanb/cancan/wiki/changing-defaults
Cancan期望在控制器中有一个current_user方法。检查是否存在

相关内容

  • 没有找到相关文章

最新更新