Working with Ruby
Hi, I am Jan. This is my old Ruby blog. I still post about Ruby, but I now do it on idiosyncratic-ruby.com. You should also install Irbtools to improve your IRB.

Troubleshooting an aegis-permission problem

In my current Rails project, I use the aegis gem for rights management. And I almost got mad, wondering, why it wouldn’t work..

Here is the code I had the problem with:

 1
2
3
4
5
6
# in models/permission.rb
permission :access_photo do |user_or_group,photo|
    allow :user do
      user_or_group.allowed_photos.first == photo
    end
  end

which was called like this (I know, it’s a little bit unDRY):

user.may_access_photo?(user,photo)

After some nerve-wracking debugging, I realized, that the first block parameter of the permission block is reserved for the “self”-user, the one on which you ask… Then, the second parameter is the first you can manually “access”. I have changed the code to:

:access_photo do |cur_user,user_or_group,photo|

Update: aegis 2 is out, and now it works as expected (without the special first block parameter). To access the user, simply call user.

Creative Commons License