2016-02-10 101 views
0

我的.each循環有一些問題。 。每次的結果在我看來顯示像JSON:每個.each的結果,Ruby on Rails

some description 這裏是我的控制器代碼:

def index 
    @articles = Article.all 
end 

這是我的觀點:

<h1>Всі статті</h1> 
<%= link_to "Нова стаття", new_article_path %> 
<table> 
    <tr> 
     <th>Заголовок</th> 
     <th>Вміст</th> 
     <th colspan="2"></th> 
    </tr> 

    <%= @articles.each do |article| %> 
     <tr> 
      <td><%= article.title %></td> 
      <td><%= article.text %></td> 
      <td><%= link_to "Переглянути", article_path(article) %></td> 
      <td><%= link_to "Редагувати", edit_article_path(article) %></td> 
     </tr> 
    <% end %> 
</table> 

什麼問題?

回答

2

<%= @articles.each do |article| %><% @articles.each do |article| %>不打印迭代

+0

感謝ü。它的作品:) – Vitaliy

+0

然後請接受答案。 – TomDunning

4

循環返回他們的陣列。 <%=正在輸出循環的返回值。刪除=。

渲染陣列:

<%= @articles.each do |article| %> 

不渲染陣列:

<% @articles.each do |article| %> 
2

去掉了 '=' 號在<%= @articles.each do |article| %> - ><% @articles.each do |article| %>

1

肯定我已經運行到同樣的問題多次。

這條線就在這裏<%= @articles.each do |article| %>不應該有等號。

0

正在顯示在再培訓局鑑於each環。每個循環都不應該有=符號,否則您將顯示整個集合。

所以把這個:

<%= @articles.each do |article| %>

進入這個:

<% @articles.each do |article| %>