makandra/aegis

Aegis 2.0: uninitialized constant Aegis::Resource

Closed this issue · 2 comments

After installing Aegis 2.0 today, I noticed that my application crashed when Aegis was hit (e.g. when the view calls a "may_index_foo?" method). The error stack trace is as follows:

ActionView::TemplateError (uninitialized constant Aegis::Resource) on line #6 of app/views/shared/_menu.html.haml:
4:   /- menu_item :groups, groups_path
5:   - menu_item :contact, contacts_path
6:   - menu_item :admin, admin_path if current_user && current_user.may_index_dashboards?

    vendor/bundler_gems/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant'
    vendor/bundler_gems/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
    vendor/bundler_gems/ruby/1.8/gems/aegis-2.0.0/lib/aegis/permissions.rb:152:in `compile'
    vendor/bundler_gems/ruby/1.8/gems/aegis-2.0.0/lib/aegis/permissions.rb:85:in `find_action_by_path'
    vendor/bundler_gems/ruby/1.8/gems/aegis-2.0.0/lib/aegis/permissions.rb:108:in `query_action'
    vendor/bundler_gems/ruby/1.8/gems/aegis-2.0.0/lib/aegis/permissions.rb:52:in `may?'
    vendor/bundler_gems/ruby/1.8/gems/aegis-2.0.0/lib/aegis/has_role.rb:66:in `send'
    vendor/bundler_gems/ruby/1.8/gems/aegis-2.0.0/lib/aegis/has_role.rb:66:in `method_missing_with_aegis_permissions'
    app/views/shared/_menu.html.haml:6:in `method_missing'
...

This issue is fixed by adding this line to the file /aegis-2.0.0/lib/aegis.rb:

require 'aegis/resource'

However, as I'm using Bundler, this fix is undone every time I deploy my code to the server. Can you verify that this is an issue and if so, apply the fix to your code?

My environment:

Rails 2.3.5
Ruby 1.8.7 patchlevel 174
Aegis 2.0.0

Thanks!

Thyraon, I pushed a new gem version 2.0.1 that includes your patch. I also added a test so we'll never forget to require a file again.

That's awesome, thanks for your quick response!