sferik/rails_admin — Issue #961: RailsAdmin broken after Rails 3.2 upgrade
Author: jerefrer
Created: 2012-02-04 15:52:22+00:00
State: open

I've just upgraded my app from Rails 3.1.0 to 3.2.0 and I am now dealing with this weird error when I go to the RailsAdmin section.

I'm using CanCan to handle the authorization and this error appears to occur only when the current_user don't have *manage :all* abilities.

So here's the error :

````
NameError in Rails_admin/main#edit

Showing /home/jeremy/.rvm/gems/ruby-1.8.7-p357/bundler/gems/rails_admin-ed0dcd1b0ebd/app/views/layouts/rails_admin/application.html.haml where line #33 raised:

undefined local variable or method `bindings' for nil:NilClass
Extracted source (around line #33):

30: %a.close{:href => '#'}×
31: %p= value
32: = breadcrumb
33: %ul.tabs
34: = menu_for((@abstract_model ? (@object.try(:id) ? :member : :collection) : :root), @abstract_model, @object)
35: = content_for :contextual_tabs
36: %span.row
Rails.root: /home/jeremy/RailsProjects/MetaTinkuy

Application Trace | Framework Trace | Full Trace
Request

Parameters:

{"sort"=>"id",
"sort_reverse"=>"false",
"id"=>"3",
"model_name"=>"user"}
````

And here is my ability.rb :

````

class Ability
include CanCan::Ability

def initialize(user)
user ||= User.new # guest user

# Admins
if user.any_role? [:super_admin, :admin, :moderator, :community_manager, :content_editor]
can :access, :rails_admin
if user.role? :super_admin
can :manage, :all
elsif user.role? :admin
can :manage, [Publication, Comment, User, Organization, Avatar, Page, Content, Follow]
can :read, Role
else
can :manage, [Publication, Comment] if user.role? :moderator
can :manage, [Page, Content] if user.role? :content_editor
if user.role? :community_manager
can :manage, [User, Avatar, Organization, Follow]
can :read, Role
end
end
end

# Normal users
if user.name # If user is logged in (because a visitor is an empty new User, so it has no name)
unless can :manage, Publication
can :read, Publication do |publication|
not publication.draft or publication.author == user
end
can :publish, Publication
can :create, Publication do |publication|
not publication.publication_type.restricted
end
can :manage, Publication do |publication|
publication.author == user and not publication.publication_type.restricted
end
can :create, Comment
can :answer, Comment do |comment|
comment.publication.author == user
end
end
unless can :manage, Organization
can :manage, Organization do |organization|
organization.users.include? user
end
end
else # If user is a visitor
can :read, Publication do |publication|
not publication.draft
end
end
end
end
````

Quick recap :
- Accessing /admin while being logged in as a SuperAdmin user (manage :all) works well
- Accessing /admin while being logged as any other kind of user throws the error shown above

What do you think ?