Rails Admin was working fine until I installed Devise_Invitable. Now, when I click on Users in Rails Admin I get the following error:
NoMethodError in RailsAdmin::MainsController#list
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
The other models work fine.
I have a hunch that this might be part of the trouble:
https://github.com/sferik/rails_admin/issues/370
as this is part of the devise_invitable
belongs_to :invited_by, :polymorphic => true
It says the issue is fixed but is there any way I don't have the most recent rails admin?
gemfile
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
Thanks for any ideas.
The answer that has you add has_many :invitees, :class_name => self.class.name, :as => :invited_by
to the User model works to get rails_admin working, but I ran into problems deleting and editing. The solution is to change the line you add to the User model to:
has_many :invitees, :class_name => "User", :as => :invited_by
Unfortunately, the stacktrace you got (and the one in that GitHub issue) is very common in rails_admin—all it really means is that an association couldn't be automatically discovered. That fix, as you found, isn't applicable to the interaction with devise_invitable.
The NoMethodError
happens because the devise_invitable gem (as of 0.5.0) only declares the belongs_to
half of the invited_by
relationship. rails_admin isn't able to fully understand this partially-declared relationship and barfs.
We were able to fix this in our app by adding the following to our Devise model:
class User < ActiveRecord::Base
# Create an explicit User.invitees => [User, User, …] relationship
# so that rails_admin can correctly discover this relationship.
has_many :invitees, :class_name => self.name, :as => :invited_by
…
end
If you'd rather not keep track of the inviter/invitee relationship at all, you could fork the devise_invitable gem and remove that functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With