Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在Rails上混合使用纯文本和HTML电子邮件?_Html_Ruby On Rails_Ruby - Fatal编程技术网

有没有办法在Rails上混合使用纯文本和HTML电子邮件?

有没有办法在Rails上混合使用纯文本和HTML电子邮件?,html,ruby-on-rails,ruby,Html,Ruby On Rails,Ruby,我正在做RubyonRails的Tutorial,我为帐户激活生成了一个Usermailer 代码如下: app/views/user\u mailer/account\u activation.text.erb Hi <%= @user.name %>, Welcome to the Sample App! Click on the link below to activate your account: <%= edit_account_activation_url(@

我正在做RubyonRails的
Tutorial,我为帐户激活生成了一个
User
mailer

代码如下:

app/views/user\u mailer/account\u activation.text.erb

Hi <%= @user.name %>,

Welcome to the Sample App! Click on the link below to activate your account:

<%= edit_account_activation_url(@user.activation_token, email: @user.email) %>
你好,
欢迎使用示例应用程序!单击下面的链接以激活您的帐户:
app/views/user\u mailer/account\u activation.html.erb

<h1>Sample App</h1>
<p>Hi <%= @user.name %>,</p>
<p>
Welcome to the Sample App! Click on the link below to activate your account:
</p>

<%= link_to "Activate", edit_account_activation_url(@user.activation_token,
                                                    email: @user.email) %>
示例应用程序
嗨

欢迎使用示例应用程序!单击下面的链接以激活您的帐户:

我理解它们之间的区别(“HTML是网页和电子邮件模板的编码方式,以便对文本进行格式化并添加图像。纯文本是常规文本,没有粗体、斜体、下划线或特殊布局选项”来源:)


但我不明白为什么有两个文件具有相同的嵌入式Ruby代码。我可以在一个文件中混合它们吗?

不,不能在一个文件中混合它们两个。Rails将分别呈现该模板的.text和.html变体,然后单击。能够显示HTML电子邮件的客户端将看到HTML变体,而仅能够显示文本的客户端将获得文本

如果需要,您可以只提供或提供其他模板,但是如果您只使用文本,那么您就不能使用HTML(显然),如果您只使用HTML,那么无法显示HTML的客户端将把HTML源代码显示为消息,使其实际上无法读取。如果您的电子邮件很简单,并且不需要标记,那么您可以只提供一个.text模板,所有内容都应该可以接受