Could not find a valid mapping for #<AdminUser ... #733

Closed
stanmx opened this Issue Nov 7, 2011 · 16 comments

Comments

Projects
None yet

stanmx commented Nov 7, 2011

Hi,

I follow the steps of https://github.com/gregbell/active_admin/wiki/Your-First-Admin-Resource%3A-AdminUser to create new users, but when i try to access other sections of active_admin i received the next message:

RuntimeError in Admin::AdminUsersController#create

Could not find a valid mapping for #<AdminUser id: 2 ....

I check the steps and my code is like the tutorial. Do you have any suggestions? thanks!

I started getting the same issue when I first had a Device instance set-up for a User model, then tried to add active_admin per the above referenced method. I too am stumped.

I am having the same issue is there no solution for this yet?

I have found the problem to be in the following line in admin_user.rb

after_create { |admin| admin.send_reset_password_instructions }

If you comment it out, it works.

Will try to further understand why, but in the meantime if you don't absolutely need this feature. It might help

I found the problem. It is in the following function inside the devise:

def self.find_scope!(duck)
    case duck
    when String, Symbol
        return duck
    when Class
        Devise.mappings.each_value { |m| return m.name if duck <= m.to }
    else
        Devise.mappings.each_value { |m| return m.name if duck.is_a?(m.to) }
    end

    raise "Could not find a valid mapping for #{duck.inspect}"
end

The problem (as discussed here: http://www.ruby-forum.com/topic/1032905) is that the provided instance of AdminUser does not respond to is_a?(AdminUser) as the two are not the same due a code reloading quirks in Rails. As it keeps happening to me in 3.1.0 it seems that it has not been resolved yet.

To avoid the problem enable the class caching in development.rb

config.cache_classes = true

Please post better solution when available

Contributor

ramigg commented Dec 3, 2011

Is there any solution for the problem except cache clases in development?

10x!

simontol commented Dec 5, 2011

Same here. Any news? Rails 3.1.3 ActiveAdmin 0.3.4

eliang commented Dec 6, 2011

+1 for a fix

chexton commented Dec 12, 2011

Confirming that I also have the same issue here. Have not yet found a suitable solution other than as mentioned above.

just add a password field to form like below:

form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
end
f.buttons
end

In the create new user page, enter a password beside the email. Also remove after_create callback in model.

fro commented Dec 19, 2011

And don't forget to restart the server if you change the development.rb file with: config.cache_classes = true

Yes, I did. Not sure why it does not show in the form for you. It just a field like other fields and nothing more.

On Dec 19, 2011, at 5:36 PM, Pourrier François wrote:

@hoangnghiem Did you try your solution? The password field doesn't show in the form.


Reply to this email directly or view it on GitHub:
gregbell#733 (comment)

fro commented Dec 19, 2011

The important thing is: It is working.

Contributor

hron84 commented Jan 17, 2012

I'd like see an another solution too... even if there is a workaround (and not a solution!) to it.

Out of curiosity do you have a "is_a?" method defined in your Admin Controller? You may be monkey patching the is_a? method on the Object class. http://ruby-doc.org/core-1.9.3/Object.html#method-i-is_a-3F

If this is the case just change your is_a? method in your Admin class to is_an? or some other method and it should work.

Contributor

gregbell commented Feb 3, 2012

The class reloading issues that caused this have been fixed in 0.4.0. Please re-open this ticket if it continues to be an issue.

@gregbell gregbell closed this Feb 3, 2012

Contributor

hron84 commented Feb 4, 2012

@gregbell and what about locale reloading issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment