Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing or Overriding ActiveAdmin Edit/Update action controller

I want to edit 'gca_user' model through ActiveAdmin after some modification, when am click on 'Update' button it Should send a email to that user.

using versions: ruby "2.1.5" Rails 4.2.1

How can i do this?

This is code: app/admin/gca_user.rb

ActiveAdmin.register GcaUser do
    permit_params :user_name, :first_name, :middle_name, :last_name, :cell_number, :social_media_provider, :social_media_id, :created_by, :created_date, :updataed_by, :updated_date, :realm, :username, :password, :credentials, :challenges, :email, :emailverified, :verificationtoken, :status, :created, :lastupdated, :provider, :nick_name

    index do
        selectable_column
        id_column
        column :user_name
        column :first_name
        column :middle_name
        column :last_name
        column :cell_number
        column :social_media_provider
        column :social_media_id
        column :created_by
        column :created_date
        column :updated_by
        column :updated_date
        column :realm
        column :username
        column :password
        column :credentials
        column :challenges
        column :email
        column :emailverified
        column :verificationtoken
        column :status
        column :created
        column :lastupdated
        column :provider
        column :nick_name
        actions
    end

    filter :id
    filter :user_name
    filter :first_name
    filter :middle_name
    filter :last_name
    filter :password
    filter :email
    filter :cell_number
    filter :social_media_provider
    filter :social_media_id
    filter :created_at
    form do |f|
        f.inputs "New User" do
            f.input :user_name
            f.input :first_name
            f.input :middle_name
            f.input :last_name
            f.input :cell_number
            f.input :social_media_provider
            f.input :social_media_id
            f.input :created_by
            f.input :created_date
            f.input :updated_by
            f.input :updated_date
            f.input :realm
            f.input :username
            f.input :password
            f.input :credentials
            f.input :challenges
            f.input :email
            f.input :emailverified
            f.input :verificationtoken
            f.input :status
            f.input :created
            f.input :lastupdated
            f.input :provider
            f.input :nick_name
        end
        f.actions
    end
end

now following is my controller:

app/controller/gca_user_controller.rb

class GcaUsersController < InheritedResources::Base
    private
    def gca_user_params
        params.require(:gca_user).permit(:user_name, :first_name, :middle_name, :last_name, :cell_number, :social_media_provider, :social_media_id, :created_by, :created_date, :updataed_by, :updated_date, :realm, :username, :password, :credentials, :challenges, :email, :emailverified, :verificationtoken, :status, :created, :lastupdated, :provider, :nick_name )
    end
end

following is my db-migrate file

-db/migrate

class CreateGcaUsers < ActiveRecord::Migration
    def change
        create_table :gca_users do |t|
            t.column :user_name, :string
            t.column :first_name, :string
            t.column :middle_name, :string
            t.column :last_name, :string
            t.column :cell_number, :string
            t.column :social_media_provider, :string
            t.column :social_media_id, :string
            t.column :created_by, :bigint
            t.column :created_date, :datetime
            t.column :updated_by, :bigint
            t.column :updated_date, :datetime
            t.column :realm, :string
            t.column :username, :string
            t.column :password, :string
            t.column :credentials, :string
            t.column :challenges, :string
            t.column :email, :string
            t.column :emailverified , :boolean
            t.column :verificationtoken, :string
            t.column :status, :string
            t.column :created, :datetime
            t.column :lastupdated, :datetime
            t.column :provider, :string
            t.column :nick_name, :string
        end
    end
end

now please tell what should i do to full fill above requirement?

like image 993
Touheed Khan Avatar asked May 30 '15 14:05

Touheed Khan


1 Answers

You can override ActiveAdmin update action of GcaUser model using below code in "app/admin/gca_user.rb"

ActiveAdmin.register GcaUser do 
  controller do
     def update(options={}, &block)
      # You can put your send email code over here 
      super do |success, failure| 
        block.call(success, failure) if block
        failure.html { render :edit }
      end
     end
  end
end
like image 80
Anant Kolvankar Avatar answered Nov 02 '22 22:11

Anant Kolvankar