【发布时间】:2015-10-29 14:26:18
【问题描述】:
场景:Backend(rails) 正在输出 Json,android 应用正在消费 json。
在应用程序中,我需要使用来自后端的 json 数据打开 Gmail 客户端(通过深度链接),以便数据是电子邮件文本并且其中包含新行。这是我尝试做的:
我尝试在视图中使用换行符发送(使用 jbuilder):
json.email "Hey Friend, <%= "\r\n"%> Some text <%= "\r\n"%> Cheers! <%= "\r\n"%> Have a great day! "
json 输出
"email": "Hey Friend, Some text Cheers! Have a great day!"
我尝试发送 html:
json.email: "<html><head></head><body>Hey Friend, <br/> <br/>Some text <br/> Cheers! <br/> Have a great day! <br/> </body></html>"
json 输出
"email": "<html><head></head><body>Hey Friend, <br/> <br/>Some text <br/> Cheers! <br/> Have a great day! <br/> </body></html>"
在 gmail 客户端使用时会输出准确的 html。
期望的输出:
你好,朋友,
一些文字
干杯!
祝你有美好的一天!
任何帮助将不胜感激!
【问题讨论】:
-
我认为这个帖子已经回答了这个问题:How to get a line break in a plain text email RoR?
-
使用
\r\n不会带来新的一行并且gmail 应用程序不会解析html -
尝试发送html表单后端并在应用程序中使用html安全。
标签: ruby-on-rails ruby json newline