스테이징 서버에서 보낸 모든 이메일에 제목 앞에 "[STAGING]"구를 사용합니다. ActionMailer를 사용하여 Rails 3.2에서이 작업을 수행하는 우아한 방법이 있습니까?스테이징 환경에서 ActionMailer 제목을 무시하십시오.
4
A
답변
16
다음은 an existing answer을 기반으로 한 ActionMailer Interceptor을 사용하여 찾은 멋진 해결책입니다.
# config/initializers/change_staging_email_subject.rb
if Rails.env.staging?
class ChangeStagingEmailSubject
def self.delivering_email(mail)
mail.subject = "[STAGING] " + mail.subject
end
end
ActionMailer::Base.register_interceptor(ChangeStagingEmailSubject)
end
0
실제로 상속은 얻을 정도로 우아합니다.
class OurNewMailer < ActionMailer::Base
default :from => '[email protected]',
:return_path => '[email protected]'
def subjectify subject
return "[STAGING] #{subject}" if Rails.env.staging?
subject
end
end
그런 다음 각 우편물을 상속 할 수 있습니다.
# modified from the rails guides
class Notifier < OurNewMailer
def welcome(recipient)
@account = recipient
mail(:to => recipient.email_address_with_name, :subject => subjectify("Important Message"))
end
end
나는이 당신을 위해 hopeing 된 것과 같은 깨끗한 생각하지 않는다, 그러나 이것은 조금을 건조합니다.
+1
관심이 있으시면 더 나은 해결책을 찾은 것 같습니다. 제가 제공 한 답을보십시오. –
+0
굉장, 고마워. :) – mwoods79
0
이
class UserMailer < ActionMailer::Base
after_action do
mail.subject.prepend('[Staging] ') if Rails.env.staging?
end
(...)
end
관련 문제
- 1. 스테이징/프로덕션 환경에서 PHPUnit을 사용해야합니까?
- 2. Hoptoad가 스테이징 환경에서 작동하도록하는 중
- 3. 레일 내 개발 환경에서 콘솔에서 스테이징 환경
- 4. 스테이징 환경에서 javascript가 실패했습니다 (jQuery 슬라이더)
- 5. 코드 호스팅은 스테이징 환경에서 어떻게 작동합니까?
- 6. ActionMailer 내가이 파일을 전송하기로했다 ActionMailer 컨트롤러가
- 7. 스테이징 테이블/스테이징 데이터베이스는 안티 패턴입니까?
- 8. .gitignore의 심볼릭 링크를 무시하십시오.
- 9. ActionMailer 대체
- 10. wicked_pdf이 ActionMailer
- 11. ActionMailer debugging
- 12. 스테이징 데이터베이스 우수 사례
- 13. UrlHelper.RouteUrl을 무시하십시오.
- 14. 문자를 무시하십시오.
- 15. 스테이징 테이블로 다중 열 업데이트 스테이징 테이블에서 널 값을 피함
- 16. ActionMailer 문자열 인코딩
- 17. utf-8 및 ActionMailer
- 18. ActionMailer Rails에서의 의심
- 19. ActionMailer 템플릿에서 time_ago_in_words 사용
- 20. 레일에 루비 ActionMailer 오류
- 21. 최대 Actionmailer 전송률 설정
- 22. 레일스 3 : ActionMailer
- 23. ActionMailer 템플릿의 연관성
- 24. Actionmailer BCC가 작동하지 않음
- 25. 레일 ActionMailer 인코딩
- 26. ActionMailer 메시지 배달 내용
- 27. ActionMailer and Ramaze
- 28. Rails ActionMailer, link_to forward?
- 29. ActionMailer 3 with Rails
- 30. Redmine Plugin의 ActionMailer 오류
가 실수로 스팸 고객을하지 않는, 그래서 당신은 당신의 자신의 이메일 수신자 데이터베이스를 사용하는지 확인 레일 4.x의 작동합니다. Thats in general ;-) – Roger