微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – 为什么字符串插值在erb模板中失败?

我在.erb文件中有以下代码
<% embed='<a href="http://someurl.com/whatever">#{@webcast.name}</a>'%>

<p id="embedCode">
    <pre>
        <code>
            <%= embed %>
        </code>
    </pre>
</p>

标记在屏幕上正确显示为文本而不是呈现为dom元素,但字符串插值失败. html已成功显示为文本,但未评估#{@webcast.name}.如果包含<%= @ webcast.name =>在模板中,成功呈现网络广播名称.

解决方法

因为没有插入用单引号”分隔的字符串.

将您的代码更改为:

<% embed = "<a href=\"http://someurl.com/whatever\">#{@webcast.name}</a>" %>

或(如果你想避免掩盖双引号字符“)

<% embed = %(<a href="http://someurl.com/whatever">#{@webcast.name}</a>) %>

或者只是(感谢Samy Dindane提示):

<% embed = "<a href='http://someurl.com/whatever'>#{@webcast.name}</a>" %>

原文地址:https://www.jb51.cc/html/226075.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐