简体   繁体   中英

rails cancan gem uninitialized constant CanCan::Ability::I18n

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

You need to install the i18n gem. Once installing, it should hopefully work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM