получить доступ к SessionsHelper изнутри почтовой программы действий Rails 3 - PullRequest
0 голосов
/ 23 августа 2011

У меня есть current_user, которого я подписываю следующим образом:

SessionsHelper.rb

  def sign_in(user)
    cookies.permanent.signed[:remember_token] = [user.id, user.encrypted_salt] 
    current_user = user 
  end

def current_user
@current_user ||= user_from_remember_token
end

 private

  def user_from_remember_token
    User.authenticate_with_salt(*remember_token) #calls the remember_token method which returns an array containing two elements. the * works to pass the values of these two elements from the array.
  end

  #returns the array that is stored in the cookie in the browser
  def remember_token
    cookies.signed[:remember_token] || [nil, nil] #if there is no cookie then return an array of two elements both nil so program does not crash
  end

Я хочу получить доступ к current_user из моей почтовой программы действий:

class ParticipantMailer < ActionMailer::Base
  add_template_helper(SessionsHelper)

обновление для включения следующего

 def welcome_Participant(participant)
      @participant = participant
      @user  = participant.user
      @board = participant.board
      @current_user = current_user
      @url   = "http://localhost:3000/#{participant.board.bp_name}/#{participant.token}"
      attachments.inline['logo.png'] = File.read(Rails.root.join('public/images/logo.png'))
      attachments.inline['cake.png'] = File.read(Rails.root.join('public/images/cake.png'))
      attachments.inline['btn-post-greeting.png'] = File.read(Rails.root.join('public/images/btn-post-greeting.png'))
      mail(:to => @user.email, :subject => "Welcome to Happy Birthday Greetings." )
    end

Но это приводит к следующей ошибке:

ActionView::Template::Error (undefined method `cookies' for #<ParticipantMailer:0x00000102f91048>):

Как я могу получить доступ к current_user из моего вида почтовой программы?

...