Sunday, November 11, 2012

[Rails] Re: gem CanCan help

[SOLVED.. I guess]

as per CanCan wiki ,  https://github.com/ryanb/cancan/wiki/Defining-Abilities-with-Blocks

I passed an Admin  scope

Admin class
  scope :employees, Admin.joins(:roles).where(:roles => { :name => "employee", :resource_type => nil}).select("DISTINCT admins.*")

in Ability model

if admin.has_role? :manager
       can [:manage, :destroy, :lock, :unlock, :reset_passord], Admin.employees


Le dimanche 11 novembre 2012 13:45:53 UTC+1, Erwin a écrit :
I defined a block in my ability model

    elsif admin.has_role? :manager
      can [:update, :destroy, :lock, :unlock, :reset_passord], Admin do |another_admin|
         another_admin.is? :employee
      end

but it seems not to be taken in account when testing it :  @manager.is?  :manager true,  @employee.is? :employee true

  test "manager_should_be_able_to_reset_employee_password" do
    sign_in  @manager
    ability = BackofficeAbility.new(@manager)
    debugger
    assert ability.can? :reset_password, @employee

looking into the ability instance , I don't see anything related to another_admin.is? :employee condition ...  => @conditions={},

#<CanCan::Rule:0x007fd92aed1718 @match_all=false, @base_behavior=true, 
@actions=[:update, :destroy, :lock, :unlock, :reset_passord], 
@subjects=[Admin(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, failed_attempts: integer, unlock_token: string, locked_at: datetime, created_at: datetime, updated_at: datetime)],
@conditions={},
@block=#<Proc:0x007fd92aed1740@/Users/yves/github/local/yoogroop/app/models/backoffice_ability.rb:26>, @expanded_actions=[:update, :edit, :destroy, :lock, :unlock, :reset_passord]>,

what's wrong with my block ?
thanks for help

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/f0z0vGc6g4kJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate