I just added active admin to my rails app and I\'m unable to create a new user. I am using the user model that active admin creates with a few added columns like first and
Upvoting @Danpe's answer. "Password" is a required field. So you need to add it to permit_params and also ask for password in the form. Only then will it save the form correctly. Here is my permit params string that also fixes other issues with creating a ActiveAdmin user mentioned here : https://github.com/gregbell/active_admin/issues/2595
controller do
def permitted_params
params.permit :utf8, :_method, :authenticity_token, :commit, :id,
model: [:attribute1, :attribute2, etc]
end
end
Forgot to add this little guy to the model...fml
after_create { |admin| admin.send_reset_password_instructions }
def password_required?
new_record? ? false : super
end
This is to do with a code reloading bug in Rails which is manifested when your environment specifies config.cache_classes = false
.
Change that to true in your config/environments/development.rb
, restart your server, and you should be able to create your user.
However that's not ideal, and one workaround suggested here is to put the following in your config/environments/development.rb
:
config.to_prepare do
Thread.current.keys.each{ |k| Thread.current[k] = nil if k.to_s =~ /_scoped_methods$/ }
end
Although the bug appears to be resolved, I see the issue in 3.1.1 which the above code fixes.
Even though this is a bug in Rails, it's also logged as a bug in active_admin if you want to see more discussion on this.
My solution:
ActiveAdmin.register User do
permit_params [:email, :password, :password_confirmation]
form do |f|
f.inputs "User" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end