ryanb/cancan — Issue #501: Ability merge
Author: rogercampos
Created: 2011-10-31 13:23:44+00:00
State: open

Hi, I've run in the following situation: I have an engine, with custom controllers and views, which is using cancan for authorization. The controllers from this engine are inheriting from the ApplicationController of the host application, which is also using cancan for their authorization system.

The thing is that I need the user to have all their abilities in place when using the engine, but the `current_ability` method is being overriden, so it loses their abilities from the host app. I need this because the app is rendering the main layout with a menu (cancan here to display the menu options) while the view is provided by the engine.

I thought it should be easy to fix, so I've made my own experiment adding a new `#merge` action to the Ability class. Now I'm able to do:

```
class SomeControllerInMyEngine < ApplicationController
def current_ability
@current_ability ||= super.merge(my_engine_ability)
end
end
```

The commit (here)[https://github.com/rogercampos/cancan/commit/7797b37c7e70a4299c144a0da5dbc3b347416715].

Is there another way to do this? Thanks!