[英]Rails, Devise, Postmark Gem - using postmark templates for devise mailer
[英]Rails 3 and devise escaping mailer templates
我正在使用rails 3並設計用於身份驗證。
將我的郵件收發器模板翻譯成除devise默認值之外的任何內容都會導致html轉義。 這樣做的一個特殊后果是,新帳戶電子郵件的確認包含無效的確認令牌。
<p><a href=3D"http://localhost:3000/users/confirmation?confirmation_token=
=3D88uo7jetcetc">Confirma=
r mi cuenta</a></p>
前面的3d是html轉義的,因此不應存在。 使用raw和html_safe對輸出沒有影響。
請注意,這種效果有時僅在控制台中存在,而在生產和/或實際發送的電子郵件中使用時則不存在。 對我來說就是這種情況; 它與非英語字符沒有關系,但是在我修改確認電子郵件(但僅在控制台輸出中)后,確實創建了上面提到的“ 3D”和“ = 3D”插入,這使測試變得復雜。
請在Devise Github上查看此問題: http : //github.com/plataformatec/devise/issues/2086 ...在這里它被稱為“ Rails問題”。
如果有人知道公開票證,我希望看到它打補丁,因為這將為許多初次接觸它的許多其他開發人員節省許多時間,並簡化所有測試。
好吧,如果有人遇到這個問題,這就是我解決的方法。
如果郵件模板包含任何非英文字符,則整個模板將被轉義。 除了在rails之前轉義所有此類字符外,似乎沒有其他方法可以解決此問題。
例如:
%p
= "!Bienvenido, #{username}!"
%p
Usted puede confirmar su cuenta a través del siguiente enlace:
%p
= link_to 'Confirmar mi cuenta', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token.html_safe)
需要
%p
= "¡Bienvenido, #{username}!"
%p
Usted puede confirmar su cuenta a través del siguiente enlace:
%p
= link_to 'Confirmar mi cuenta', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token.html_safe)
我也有這個問題。 一旦我使用rails link_to
方法, html_safe
起作用。
%a{:href => "#{@redemption.link.html_safe}"}= "http://example.com/#{@redemption.model.email_hash}"
= link_to "http://example.com/#{@redemption.model.email_hash}", @redemption.link.html_safe
我可以確認在控制台中收到了這樣的電子郵件消息(帶有3D開頭),但在實際發送的消息中卻沒有 。 因此,無需逃避任何事情。
但是,出於測試目的,您可以添加以下代碼以僅在開發人員模式下在控制台中顯示電子郵件:
<% if Rails.env.development? %>
<% logger.debug confirmation_url(@resource, confirmation_token: @token) %>
<% end %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.