CanCan未初始化的常数Ability :: CanCan [英] CanCan uninitialized constant Ability::CanCan

查看:113
本文介绍了CanCan未初始化的常数Ability :: CanCan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道我在这里可能做错了什么吗?我知道说能力不是可以的吗? :manage,all;但是我只是想开始使用CanCan。

Any idea what I could be doing wrong here? I know it's not very useful to say ability.can? :manage, all; however I'm just trying to get started with CanCan.

我确实拥有gem,并且运行了generate cancan:ability。

I do have the gem, and have run generate cancan:ability.

谢谢。

错误和代码:

未初始化的常数Ability :: CanCan
提取的源(第4行附近):

uninitialized constant Ability::CanCan Extracted source (around line #4):

1: 
2: <% if current_user %>
3:     <p>Currently logged in as <strong><%= current_user.email %></strong></p>
4:     <% current_ability = Ability.new(current_user) %>
5:     <%if can? :manage, :all %>
6:      <p>Hey Buddy, You're Authorized ;)</p>
7:     <% end %>


推荐答案

我收到此错误是因为我的Gemfile放置了CanCan要求

I received this error because my Gemfile placed the CanCan requirement in a group that was not being loaded in the test environment.

请尝试检查您的CanCan要求是否已在运行的环境中加载。此要求将CanCan加载到默认组中:

Try checking to see that your CanCan requirement is loaded in the environment you're running. This requirement will load CanCan in the default group:

# project_root/Gemfile
source 'http://rubygems.org'

gem 'rails', '3.1.0'
gem 'cancan'

这篇关于CanCan未初始化的常数Ability :: CanCan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆