为什么 Rails 应用程序在底部显示数据库信息? [英] Why Rails app showing database information at the bottom?

查看:33
本文介绍了为什么 Rails 应用程序在底部显示数据库信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个博客.每当我添加一个帖子时,总会有一个来自数据库的记录列表显示在帖子索引页面的底部 (home.html.erb),如下所示:

I have created a blog. And whenever I added a post, there is always a list of record from the database showing at the bottom of the post index page (home.html.erb), like this:

[#<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 %> 但它不起作用.

I've tried to remove <%= will_paginate @posts %> but it doesn't work.

这是我的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 以备不时之需:

Here's my Gemfile just in case you need it:

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'

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

This is a weird situation. So I want to know what happened?

谢谢!

推荐答案

从 -

<%= @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 %>

到 -

<% @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 %>

它出现是因为你使用了 <%= @posts.each do |post|%> 而不是 <% @posts.each do |post|%>.<%= %> 将输出返回值,但 <% %> 不会

It shows up because you are using <%= @posts.each do |post| %> instead of <% @posts.each do |post| %>. <%= %> will output the return but <% %> won't

这篇关于为什么 Rails 应用程序在底部显示数据库信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆