Can't create new user with ActiveAdmin

前端 未结 4 1771
南笙
南笙 2020-12-20 06:31

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

相关标签:
4条回答
  • 2020-12-20 06:42

    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
    
    0 讨论(0)
  • 2020-12-20 06:56

    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
    
    0 讨论(0)
  • 2020-12-20 06:59

    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.

    0 讨论(0)
  • 2020-12-20 07:00

    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
    
    0 讨论(0)
提交回复
热议问题