2013-02-25 75 views
0

這是我對我的職位代碼/ index.html.erb文件:老HTML生產增加在Heroku和Rails 3.2.1

<!-- 
    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上的時候將其放在那裏?

回答

1

這是你的罪魁禍首。 "#{post.title}".html_safe

您顯示的其中一個帖子的標題中有html標籤。對用戶輸入的任何內容致電.html_safe是個壞主意。您應該使用h(post.title)來避開該錯誤,或​​者首先爲已接受的標記清理字符串。看看sanitize helper

+0

謝謝,是的,我完全忘了我已經在標題中換了一個換行符,並且因爲我使用Mercury編輯器,它將該換行符翻譯爲


。 – kwyoung11 2013-02-26 01:45:18