Reputation: 161
I first installed devise and altered it so I can login with username instead of email. After that I entered the Activeadmin gem into my gem file.
After that I did a bundle install and rake active_admin:install. But after trying to log into the backend /admin/login I see this error message :
undefined method `username' for #<AdminUser:0x00000004bb2e58>
On this code :
Extracted source (around line #7):
4: <% scope = Devise::Mapping.find_scope!(resource_name) %>
5: <%= active_admin_form_for(resource, :as => resource_name, :url => send(:"#{scope}_session_path"), :html => { :id => "session_new" }) do |f|
6: f.inputs do
7: resource.class.authentication_keys.each { |key| f.input key, :input_html => {:autofocus => true}}
8: f.input :password
9: f.input :remember_me, :label => t('active_admin.devise.login.remember_me'), :as => :boolean, :if => false #devise_mapping.rememberable? }
10: end
Anyone a idea how to solve this ? If you need more info just ask.
Roelof
edit : I thought I could solve this by doing this: http://blog.blazingcloud.net/2012/07/29/activeadmin-with-existing-devise-authentication/ But now all the login are failed ( 401) where they without activeadmin they were successfull
Upvotes: 3
Views: 1142
Reputation: 2498
I was having the same error and I solved it adding this to my AdminUser model
def login=(login)
@login = login
end
def login
@login || self.email
end
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
where(conditions).where(["lower(email) = :value", { :value => login.strip.downcase }]).first
end
Upvotes: 1