问题
I'm just making a newsfeed that is database driven, right now I have it working, but at the end of every news post, I get a string like so:
21 <div id='newsfeed'>
22 <%= @news.each do |new| %>
23 <div class='span10'>
24 <h3><%= new.title %></h3>
25 <p class='muted'><%= new.date %></p>
26 <p><%= new.body %></p>
27 </div>
28 <% end %>
29 </div>
30 </div>
and then my controller has this:
def home
@news = Newsfeed.all
end
Yet the output looks like this:

It would work great if it didn't post the entire array, I'm not sure why it would.. Thanks!
回答1:
You should use "silent"
<% @news.each do |new| %>
instead of
<%= @news.each do |new| %>
回答2:
Remove the equals sign on line 22:
21 <div id='newsfeed'>
22 <% @news.each do |new| %>
23 <div class='span10'>
24 <h3><%= new.title %></h3>
25 <p class='muted'><%= new.date %></p>
26 <p><%= new.body %></p>
27 </div>
28 <% end %>
29 </div>
30 </div>
来源:https://stackoverflow.com/questions/16844467/database-driven-content-printing-its-full-db-string-to-page-when-no-code-told-to