4

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?

ciembor
  • 7,189
  • 13
  • 59
  • 100

3 Answers3

3

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
Cedric Loy
  • 61
  • 1
  • 7
0
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.

Orlando
  • 9,374
  • 3
  • 56
  • 53
-1

At your /app/models/user.rb

  before_create :skip_confirmation

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