Activeadmin docs are very easy on how to override the action of a standard controller, which is disappointing given how opaque the source code is. Many of the internal elements in the stone seem to have changed a ton with version 1.0, which renders many old stack overflow responses unusable.
In any case, here is how I was above to override the #create action in my activeadmin controller (on Rails 4.2.x):
controller do def create @user = User.create_from_admin(permitted_params[:user]) if @user.persisted? redirect_to resource_path(@user), notice: I18n.t("admin.user.create.notice") else render :action => :new end end end
It is worth noting that activeadmin expects, if your model is a user, for the create action to have a populated instance of the model as @user before it can display action => :new .
I wrote the insides of my custom creation method as a class method on my model so that I can test it and bury as little code as possible in my activeadmin code.
For context, I needed to override this action because I use Devise, and I wanted my admins to create user accounts with a temporary password and a custom greeting email, not built-in: a confirmed email for self-creation of an account.
Here is this user class method:
def self.create_from_admin(params) generated_password = Devise.friendly_token.first(8) @user = User.new(params) @user.password = generated_password @user.skip_confirmation! if @user.save
source share