[英]Rails replacing '\n' to '<br/>' issue
The input is a textarea type 输入是文本区域类型
so i got the data from the controller like this, 所以我像这样从控制器获取数据,
'firstline \n secondline \n thirdline"
i want to change this to 我想将其更改为
'firstline <br/> secondline <br/> thirdline"
I googled, and found this. 我用谷歌搜索,发现了这个。
description = appointment[:description].to_s.gsub(/\n/, "<br/>")
but the weird thing is if i print this, it shows a weird text like this, 但是很奇怪的是,如果我打印出这个字样,它会显示出这样一个奇怪的文字,
code, 码,
<%=Rails.logger.debug("***description***" + description)%>
result, 结果,
<br/>3rd linen***1st line
the more weird thing is, i have to put this params to call a javascript function like this, 更奇怪的是,我必须将这些参数放在这样的javascript函数中,
<span class="hotspot" onmouseover="tooltip.show(<%=user_list%>,"<%=description%>");" onmouseout="tooltip.hide();">
<%=h appointment[:users] %>
</span>
focus on the <%=description%> 专注于<%= description%>
in here i got an error, and shows like this, 在这里,我遇到了一个错误,并显示了这样的内容,
<span class="hotspot" onmouseover="tooltip.show([],"1st line
<br/>2nd line
<br/>3rd line");" onmouseout="tooltip.hide();">
Uncaught SyntaxError: Unexpected token ILLEGAL
any good idea? 有什么好主意吗?
尝试这个
"firstline \n secondline \n thirdline".to_s.gsub(/\n/, "<br/>").html_safe
May be this will work 也许这会工作
desc = appointment[:description].to_s
description = desc.split("\n").join("<br/>")
尝试这个。
description = appointment[:description].to_s.gsub(/\n/, "<br/>").html_safe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.