On 26 March 2016 at 09:55, Naveed Alam <li...@ruby-forum.com> wrote: > Colin Law wrote in post #1182464: >> On 26 March 2016 at 09:30, Naveed Alam <li...@ruby-forum.com> wrote: >>> You might have expected an instance of ActiveRecord::Base. >>> The error occurred while evaluating nil.[] >>> >>> app/models/privilege.rb:24:in `applicable?' >> >> The error says you have called the method [] on an object that is nil. >> You don't seem to have shown us line 24 of privilege.rb (and the >> surrounding lines). >> >> Colin > > class Privilege < ActiveRecord::Base > has_and_belongs_to_many :users > belongs_to :privilege_tag > > def applicable? > role_plugin_hash = > Authorization::Engine.instance.roles_plugin_hash[self.name.underscore.to_sym]
You have not told us which is line 24, but I assume it is the one above, in which case roles_plugin_hash is nil. > role_plugin_hash.nil? ? false : (role_plugin_hash.include? nil) ? > true : (role_plugin_hash & FedenaPlugin.accessible_plugins).present? ? > true : false That is horrible. A classic case of saving a few lines of code and making it difficult to understand what the code is doing. I just hope your automated tests check all the possible conditions on this. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu2kV%3DVK0d7uQE%3Dgfq7vsiYhUpYSKdtVfG67YZo3C5whQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.