2014-10-20 24 views

回答

1

你需要遍歷問題並輸出任何你想要的HTML結構。

例如,作爲一個無序列表:

<ul> 
    <% @questions.each do |question| %> 
    <li><%= question.title %></li> 
    <% end %> 
</ul> 
1

要列出索引頁面上的問題的代碼應該是這樣的,如下所示:

<table> 
    <tr> 
    <th>Title</th> 
    <th>Description</th> 
    </tr> 
    <% @questions.each do |question| %> 
    <tr> 
     <td><%= question.title %></td> 
     <td><%= question.description %></td> 
    </tr> 
    <% end %> 
</table> 
1

@questions是一個集合,你要麼需要遍歷視圖中的集合或將其傳遞給部分名爲_question.html.erb的部分。如果你創建一個局部命名_question.html.erb這樣

<% @questions.each do |question| %> 
    <p>question.title</p> 
<% end %> 

否則:

<p><%= question.title %><p> 
在你的主視圖

然後你可以通過@questions對象到部分喜歡這一點,它遍歷你可以這樣做將打印@questions集合的所有成員

<% render @questions %> 
相關問題