ryanb/cancan — Issue #558: Trouble defining or checking ability by class name. 
Author: nkxx
Created: 2012-02-09 00:54:27+00:00
State: open

Hi Ryan,

I am new to RoR. I am guessing I am doing something wrong. When defining an ability "can :manage, :all" works but when a Class name is used, it does not.

Thank you
NK

app/models/ability.rb
include CanCan::Ability
def initialize(user)
if user
groups = user.group_strings.split(",")
groups.each { |adgroup|
adgroup.strip!
case adgroup
when "storemanager"
#
# The user with the group membership was logged on during both tests.
#
# This does not work but no error is raised
# can :manage, Store
#
# This works but isn't what I need
can :manage, :all
end
}
end

end
end

app/views/stores/index.html.erb
....
<% if can? :update, @store %>
<%= link_to 'Edit', edit_store_path(store) %>
<% end %>
....

ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

gem 1.8.10

cancan (1.6.7)