Trouble defining or checking ability by class name. #558

Closed
nkxx opened this Issue Feb 9, 2012 · 3 comments

Projects

None yet

3 participants

@nkxx
nkxx commented Feb 9, 2012

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)

@nkxx
nkxx commented Feb 9, 2012

Never mind. I figured it out. Switched the ability checking to class.

@jnv
jnv commented Feb 9, 2012

Have you tried to define abilities using the symbols instead of classes as described in CanCan 2.0? For example:

can :manage, :stores

However class name should still work, at least according to spec.

@nkxx
nkxx commented Feb 9, 2012

yes I eventually switched to symbols and that worked too.

@Gimi Gimi closed this May 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment