0
votes

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.

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

Thanks.

Error and Code:

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 %>
1

1 Answers

1
votes

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

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'