如何在 rails 上的 ruby 中获取换行分隔的文本
How to get new line separated text in ruby on rails
场景:后端(rails)正在输出 Json,android 应用正在消耗 json。
在应用程序中,我需要使用来自后端的 json 数据打开 Gmail 客户端(通过深度链接),以便数据是电子邮件文本并且其中有新行。这是我尝试做的:
I tried sending with new line characters in my view(using 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!"
I tried sending 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。
期望输出:
嘿朋友,
一些文字
干杯!
祝你有愉快的一天!
任何帮助将不胜感激!
您的代码中似乎存在一些引用问题。我将 \r\n 移到一个单独的变量中并用于 JSON:
line_break = "\r\n"
json.email "Hey Friend, #{line_break} Some text #{line_break} Cheers! #{line_break} Have a great day!"
场景:后端(rails)正在输出 Json,android 应用正在消耗 json。
在应用程序中,我需要使用来自后端的 json 数据打开 Gmail 客户端(通过深度链接),以便数据是电子邮件文本并且其中有新行。这是我尝试做的:
I tried sending with new line characters in my view(using 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!"
I tried sending 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。
期望输出:
嘿朋友,
一些文字
干杯!
祝你有愉快的一天!
任何帮助将不胜感激!
您的代码中似乎存在一些引用问题。我将 \r\n 移到一个单独的变量中并用于 JSON:
line_break = "\r\n"
json.email "Hey Friend, #{line_break} Some text #{line_break} Cheers! #{line_break} Have a great day!"