Rails cancan gem 未初始化常量 CanCan::Ability::I18n
我想使用 cancan (由 Ryan Bates 编写)禁用具有“作者”角色的用户对页面控制器的访问。
PagesController 如下
class PagesController < ApplicationController
def new
@page = Page.new
authorize! :update, @page
...
end
...
end
这是返回未初始化的常量 CanCan::Ability::I18n 请注意,当我使用时也会发生同样的事情 加载和授权资源 过滤而不是 授权! :更新,@page
我正在使用 Rails 2.2.3。 有人遇到过类似的问题吗? 谢谢
添加ability.rb代码:
class Ability
include CanCan::Ability
def initialize(current_user)
user = User.find(:first, :conditions => ["username = ?", current_user])
user ||= User.new # guest user
if user.role?('admin')
can :manage, :all
can :manage, WpArticle
elsif user.role?('moderator')
can :manage, :all
elsif user.role?('author')
can :create, WpArticle
can :update, WpArticle
can :read, WpArticle
end
end
end
I want to disable access to a Pages controller for users having role "author", using cancan (by Ryan Bates).
The PagesController is as follows
class PagesController < ApplicationController
def new
@page = Page.new
authorize! :update, @page
...
end
...
end
This is returning uninitialized constant CanCan::Ability::I18n
Note that the same thing happens when I use
load_and_authorize_resource
filter instead of
authorize! :update, @page
I am using Rails 2.2.3.
Has anyone encountered a similar issue?
Thanks
Adding the ability.rb code:
class Ability
include CanCan::Ability
def initialize(current_user)
user = User.find(:first, :conditions => ["username = ?", current_user])
user ||= User.new # guest user
if user.role?('admin')
can :manage, :all
can :manage, WpArticle
elsif user.role?('moderator')
can :manage, :all
elsif user.role?('author')
can :create, WpArticle
can :update, WpArticle
can :read, WpArticle
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要安装 i18n gem。安装后,它应该可以工作。
You need to install the i18n gem. Once installing, it should hopefully work.