Database driven content printing its full DB string to page when no code told to do so?

。_饼干妹妹 提交于 2019-12-25 07:20:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!