2011-03-01 48 views
0

我有一個應用程序,我想要使用「content_for」以及左側導航欄來呈現菜單,然後其餘部分是我的文檔的主體。但是,在我的左欄和菜單區域中,html標記正在被轉義。我看到一篇關於在收益率之前使用原材料的帖子,但這沒有幫助。rails 2.3.7內容的問題

花了相當一段時間在真實應用程序中嘗試診斷它之後,我創建了一個非常簡單的測試,並且能夠用最少的代碼來完成它。以下是我有:

layouts.application.erb

<body> 
    <section id="page"> 
     <header> 
      <nav class="clear"><%= raw yield :navigation %></nav> 
     </header> 

     <%= yield %> 

    </section> 
    </body> 
</html> 

頁/ index.html.erb

<% content_for :navigation do %> 
    <ul><li><%= link_to 'New page', new_page_path %></li></ul> 
<% end %> 

<h1>Listing pages</h1> 

<table> 
    <tr> 
    <th>Title</th> 
    <th>Body</th> 
    </tr> 

<% @pages.each do |page| %> 
    <tr> 
    <td><%=h page.title %></td> 
    <td><%=h page.body %></td> 
    <td><%= link_to 'Show', page %></td> 
    <td><%= link_to 'Edit', edit_page_path(page) %></td> 
    <td><%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %></td> 
    </tr> 
<% end %> 
</table> 

當我在瀏覽器中點擊的頁面,導航部分(實際上是鏈接,但不是列表,這對於菜單來說有點重要:))

這是來自一個全新的rails pro ject使用腳手架生成的代碼,只是修改默認鏈接到導航部分(並添加該部分)。

回答

0

當您將內容放置在一邊而不是顯示時,轉義就會發生。嘗試在content_for內使用raw

<% content_for raw :navigation do %>