Ruby on rails 在控制器中定义的邮件程序中使用帮助器方法

Ruby on rails 在控制器中定义的邮件程序中使用帮助器方法,ruby-on-rails,ruby,helper,Ruby On Rails,Ruby,Helper,助手方法current\u user在ApplicationController中定义并作为助手提供,如下所示: class ApplicationController < ActionController::Base helper_method :current_user def current_user return @current_user if defined?(@current_user) @current_user = curren

助手方法
current\u user
ApplicationController
中定义并作为助手提供,如下所示:

class ApplicationController < ActionController::Base
  helper_method :current_user
    def current_user
        return @current_user if defined?(@current_user)
        @current_user = current_user_session && current_user_session.record
    end
end
class ApplicationController
我的问题是如何在mailer模板中使用
current\u user
helper方法(显然它总是返回
nil
,但我正在尝试渲染依赖于它的部分)


通常,当我想在邮件程序中使用帮助程序时,我会执行类似于添加模板帮助程序(SongsHelper)
的操作,但是由于帮助程序是在类中定义的,而不是在模块中定义的,所以我不确定该做什么

我喜欢在变量中传递用户,然后在模板中使用它。它将当前用户的呼叫传递给控制器(我通常从控制器发送邮件)


另一个解决方案是将
current\u user
和支持的方法放入一个模块中,并将其混合到两个ApplicationController中,还可以与类中继承自ActionMailer::Base的
helper
方法一起使用。看看您是否对这个方法感兴趣。

我在一个mailer方法参数中传递了controller方法的返回值
UserMailer.invitation(@invitation,current_organization)。在
ApplicationController中定义当前_组织的位置传递