gpt4 book ai didi

html - 使用 Rails 3.2.1 在 Heroku 上生产中添加的旧 HTML

转载 作者:太空宇宙 更新时间:2023-11-04 15:15:00 25 4
gpt4 key购买 nike

这是我的 posts/index.html.erb 文件的代码:

<!--
Iterate over each post in list format
-->
<% @posts.each do |post| %>
<ul class="posts">
<!--
Link to article, display date created, show edit, delete links if logged in
-->
<li><%= link_to "#{post.title}".html_safe, post, id: "article" %></li>
<li id="date"> <%= post.created_at.strftime("%B %Y") %></li>

<% if logged_in? %>
<li>
<%= link_to 'Edit', "/editor" + post_path(post), id: "edit_delete", data: {save_url: mercury_update_post_path(post)} %>
<%= link_to 'Delete', post, id: "edit_delete", :method => :delete %>
</li>
<% end %>
</ul>
<% end %>

在我的本地开发和生产环境中,关联的 css 样式表和 html 可以在浏览器中正确编译和呈现。但是,当我将此代码部署到 heroku 时,它添加了一些我之前删除的旧 HTML,如页面源代码所示:

    <!--
Iterate over each post in list format
-->
<ul class="posts">
<!--
Link to article, display date created
-->
<li> <a href="/posts/5" id="article"><b>Endurance Exercise is Bad for your Health?</b>
<div><b><br></b></div></a> </li>
<li id="date"> February 2013 </li>

<!--
Show edit, delete links if logged in
-->
</ul>

参见 <div><b><br></b></div>嵌入在文章“耐力锻炼对健康有害?”链接标签中的标签...任何人都知道为什么在生产环境中部署到 heroku 时将它放在那里?

最佳答案

这是你的罪魁祸首。 "#{post.title}".html_safe

您正在显示的其中一个帖子的标题中有 html 标签。对用户输入的任何内容调用 .html_safe 是个坏主意。您应该使用 h(post.title) 转义它,或者首先为接受的标签清理字符串。看sanitize helper

关于html - 使用 Rails 3.2.1 在 Heroku 上生产中添加的旧 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15078750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com