2012-01-21 2 views
1

어떤 이유인지이 인스턴스의 변수가이 ActionMailer에 설정되어 있지 않습니다. 다른 ActionMailers는 정상적으로 작동하는 것 같습니다. 어떤 아이디어가이 원인 일 수 있습니까? UserMailer는 제한된 단어 perpahps입니까?내 인스턴스 변수가 내 조치 메일러보기에서 설정되지 않는 이유는 무엇입니까?

return unless user and user.email and not user.confirmed_at 

이메일을 전송 중단하지 않았다 :

사용 레일

# app/mailers/user_mailer.rb 

class UserMailer < ActionMailer::Base 
    default from: 'My Name <[email protected]>' 

    def registration_confirmation(user) 
    # Don't send email if we don't have an email address to send it to or the user is already confirmed 
    return unless user and user.email and not user.confirmed_at 

    # Set global variable for mail view 
    @my_message = 'Hello world!' 

    # Send email 
    mail(to: "#{user.name} <#{user.email}>", subject: 'Please confirm your email address') 
    end 

end 


# app/views/user_mailer/registration_confirmation.text.erb 

Hello who? <%= @my_message %> # Simply returns 'Hello who? ' 

답변

1

3.1이 줄을 끈다. 대신 위의 UserMailer 코드를 중단하고 설정되지 않은 인스턴스 변수를 나타내는 뷰로 곧바로 이동합니다. 따라서 본질적으로 ActionMailer는 일반 컨트롤러와 똑같이 작동합니다.

나는이 문제를 해결하기 위해 UserMailer 명령을 실행하는 곳으로 전자 메일을 보낼지 여부를 확인하는 조건을 변경했습니다.

0

변경 사항이 반영된 경우 서비스 및 근로자를 다시 시작해야합니다.

관련 문제