Tar*_*her 2 device cancan ruby-on-rails-3
我得到了
undefined local variable or method `current_user` error for
Run Code Online (Sandbox Code Playgroud)
在我看来由以下代码引起
<% if can? :update, Project %>
<span class="admin">
<%= link_to 'Nieuw Project', new_project_path %>
</span>
<% end %>
Run Code Online (Sandbox Code Playgroud)
当我删除代码时,页面呈现正确.
CanCan代码:
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
Run Code Online (Sandbox Code Playgroud)
用户模型:
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
Run Code Online (Sandbox Code Playgroud)
我的应用程序的规格
- rails 3.0.3
- 设计1.5.3
- 设计不可思议的0.6.0
- 康康1.6.4
也许你正在考虑关于康康和设计的这个小细节.https://github.com/ryanb/cancan/wiki/changing-defaults
Cancan期望一种current_user方法可以在您的控制器中.检查是否存在.
| 归档时间: |
|
| 查看次数: |
2684 次 |
| 最近记录: |