Reputation: 143
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
Upvotes: 0
Views: 807
Reputation: 356
You need to install the i18n gem. Once installing, it should hopefully work.
Upvotes: 0