为什么 Rails 应用程序在底部显示数据库信息?

2024-06-19

我创建了一个博客。每当我添加帖子时,帖子索引页面底部总会显示数据库中的记录列表(home.html.erb), 像这样:

[#<Post id: 1, title: "hahaha", content: "Because the gravatar_for method is undefined, the u...", public: true, created_at: "2013-03-18 04:00:17", updated_at: "2013-03-18 04:01:09">] 

我尝试删除<%= will_paginate @posts %>但它不起作用。

这是我的home.html.erb:

<%= @posts.each do |post| %>
<article class="posts">
    <h2><%= link_to post.title, post_path(post) %></h1>
    <h3><%= post.public %></h3>
    <p><%= truncate markdown(post.content), length: 400, omission: " ......" %></p>
    <span class="continue"><%= link_to "... Continue Reading ...", post_path(post) %></span>
</article>
<% end %>
<%= will_paginate @posts %>

这是我的 Gemfile,以防万一您需要它:

source 'https://rubygems.org'

gem 'rails', '3.2.12'
gem 'pg'
gem 'redcarpet'
gem 'will_paginate'
gem 'redcarpet'
gem 'coderay'

group :development, :test do
  gem 'rspec'
  gem 'rspec-rails'
  gem 'faker' 
end

group :test do
  gem 'capybara'
  gem 'factory_girl_rails'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

gem 'bcrypt-ruby', '~> 3.0.0'

这是一个奇怪的情况。所以我想知道发生了什么?

谢谢你!


更改您的模板文件 -

<%= @posts.each do |post| %>
<article class="posts">
  <h2><%= link_to post.title, post_path(post) %></h1>
  <h3><%= post.public %></h3>
  <p><%= truncate markdown(post.content), length: 400, omission: " ......" %></p>
  <span class="continue"><%= link_to "... Continue Reading ...", post_path(post) %></span>  
  </article>
  <% end %>
<%= will_paginate @posts %>

to -

<% @posts.each do |post| %>
  <article class="posts">
  <h2><%= link_to post.title, post_path(post) %></h1>
  <h3><%= post.public %></h3>
  <p><%= truncate markdown(post.content), length: 400, omission: " ......" %></p>
  <span class="continue"><%= link_to "... Continue Reading ...", post_path(post) %>  </span>
 </article>
<% end %>

它出现是因为您正在使用 而不是 . 将输出返回值,但 不会

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 Rails 应用程序在底部显示数据库信息? 的相关文章

随机推荐