3
votes

I want to call user.skip_confirmation while his account is created by admin in admin panel. I want user to confirm his account in further steps of registration process, but not on create. The only idea I have is to override create in controller:

controller do
  def create
    user = User.new
    user.skip_confirmation!
    user.confirmed_at = nil
    user.save!
  end
end

The problem is, I have different attr_accessibles for standard user and admin, and it works, because ActiveAdmin uses InheritedResources:

attr_accessible :name, :surname
attr_accessible :name, :surname, invitation_token, :as => :admin

It doesn't work after I changed create (it worked before). How can I do what I want and still be able to use this :as => :admin feature?

3

3 Answers

2
votes

I look at the answer and none is solving the issue at hand. I solve it the simplest way as shown below.

before_create do |user|
 user.skip_confirmation!
end
0
votes
controller do
  def create
    @user = User.new(params[:user].merge({:confirmed_at => nil}))
    @user.skip_confirmation!
    create! #or super
  end

  def role_given?
    true
  end

  def as_role
    # adapt this code if you need to
    { :as => current_user.role.to_sym } 
  end
end

something like that could work

EDIT: if you define role_given? to return true and as_role, InheritResources will use as_role to get the role information

also

controller do
  with_role :admin
end

works, but this way you can't change the role given the user.

0
votes

At your /app/models/user.rb

  before_create :skip_confirmation

  def skip_confirmation
    self.skip_confirmation! if Rails.env.development?
  end