在下面的课程中,如何在email_confirmation
回调password_reset
旁边获取当前操作名称(例如after_action
,add_mandril_headers
)?
class UserMailer < ActionMailer::Base
after_action :add_mandril_headers
def email_confirmation(user)
mail(..)
end
def password_reset(user)
mail(..)
end
private
# how to get the action name?
def add_mandrill_headers
headers['X-MC-Tags'] = [mailer_name, action_name].join('_');
end
end
答案 0 :(得分:15)
结果action_name
返回当前的邮件程序操作名称。我基于ActionController
具有类似方法的事实尝试了它。
答案 1 :(得分:1)
谢谢@HarishShetty!
正如您所提到的,action_name
适用于所有控制器,因为它继承自ApplicationController
。
例如,我使用public_activity并希望在我的控制器中进行一些简化:
class SiteDetailsController < ApplicationController
after_action :track_activity, only: [:create, :update, :destroy]
# ...
private
def track_activity
@site_detail.create_activity action_name, owner: current_user
end
end