Reputation: 1425
After so much searching I finally found a way to add a new button to ActiveAdmin default template. Following is my User.rb file where I am adding a new button
action_item only: :show do
link_to "Resend Email"
end
Currently it's routing to show action when clicked. But I wanted to route it to UserMailer#confirmation_instructions
routes.rb
Rails.application.routes.draw do
ActiveAdmin.routes(self)
devise_for :users,controllers: {registrations: 'users/registrations',sessions: 'users/sessions',confirmations: 'users/confirmations'}
end
Usermailer.rb
def confirmation_instructions(record, token, opts={})
@system_email = SystemEmail.find_by(title: 'Email Verification')
@subject = @system_email.try(:subject).to_s
@subject = "Email Verification" if @subject.blank?
opts = {subject: @subject}
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
How can I can route it to UserMailer#confirmation_instructions
?? This AI have done these things on normal MVC architecture. But this is really eating my head. Can somebody please tell how can I achieve that?
Upvotes: 0
Views: 139
Reputation: 52357
It should be something along these lines:
action_item only: :show do
link_to(
'Resend email',
resend_email_admin_user_path(user_id: user.id),
data: { confirm: 'Are you sure you want to resend it?' }
)
end
member_action :resend_email do
user = User.find(params[:user_id])
UserMailer.confirmation_instructions(user, user.token, {})
redirect_to admin_user_path(user), notice: 'confirmation is sent'
end
Upvotes: 1