[英]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.经过一些修改后,我想通过 ActiveAdmin 编辑“gca_user”model,当我点击“更新”按钮时,它应该向该用户发送 email。
using versions: ruby "2.1.5" Rails 4.2.1使用版本:ruby "2.1.5" Rails 4.2.1
How can i do this?我怎样才能做到这一点?
This is code: app/admin/gca_user.rb这是代码: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:现在下面是我的 controller:
app/controller/gca_user_controller.rb应用程序/控制器/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 文件
-db/migrate -db/迁移
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?现在请告诉我应该怎么做才能完全满足上述要求?
You can override ActiveAdmin update action of GcaUser model using below code in "app/admin/gca_user.rb"您可以使用“app/admin/gca_user.rb”中的以下代码覆盖 GcaUser 模型的 ActiveAdmin 更新操作
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
You can simply override a controller action by using:您可以使用以下命令简单地覆盖 controller 操作:
controller do
def update
@product = Product.find params[:id]
photos_params = params[:product][:photos] if params[:product][:photos].present?
params[:product].reject! { |p| p["photos"] }
if photos_params.present?
photos_params.each do |photo|
@product.photos.attach(photo)
end
end
super
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.