如何删除Post.all @静态页面下的节点

时间:2015-04-04 02:45:08

标签: ruby-on-rails

在我的应用程序中,当我在静态页面主页中呈现Post.all时,我在页面末尾会得到一些这样的代码

[#<Post id: 3, title: "I loved you...", content: "how to short and place enter if the line is large ...", created_at: "2015-04-03 09:17:48", updated_at: "2015-04-03 10:34:47", image_file_name: "Penguins.jpg", image_content_type: "image/jpeg", image_file_size: 777835, image_updated_at: "2015-04-03 09:18:50">, #<Post id: 2, title: "I loved you...", content: "I loved you, and I probably still do,\r\nAnd for a w...", created_at: "2015-04-02 15:44:19", updated_at: "2015-04-02 15:44:19", image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil>, #<Post id: 1, title: "উত্তম ও অধম", content: "কুকুর আসিয়া এমন কামড়\r\nদিল পথিকের পায়\r\nকামড়ের চ...", created_at: "2015-04-02 15:41:51", updated_at: "2015-04-02 15:41:51", image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil>]

如何删除或停止获取?

这是我的宝石文件

source 'https://rubygems.org'



gem 'rails', '4.2.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.1.0'

gem 'therubyracer', platforms: :ruby

gem 'jquery-rails'

gem 'paperclip', '~> 4.2.1'

gem 'turbolinks'

gem 'jbuilder', '~> 2.0'

gem 'sdoc', '~> 0.4.0', group: :doc




group :development, :test do
  gem 'sqlite3'
  
  gem 'byebug'

 
  gem 'web-console', '~> 2.0'
end

group :production do
  gem 'pg'
  
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

在Pages控制器主页操作中,我放了@post = Post.all

并且在视图中我已经放了

<%= @post.each do |post|%>
<% if post.image.present?%>

<h1> <%= link_to post.title, post %></h1><br>

<%= image_tag post.image.url(:thumb)%>

<%= simple_format post.content %>
<hr color="blue" >
<% else %>

<h1> <%= link_to post.title, post %></h1><br>
<%= simple_format post.content %>
<hr color="blue">

<% end %>

<%end%>

1 个答案:

答案 0 :(得分:1)

您应该删除第一个循环=

中的<%= @post.each do |post|%>
<% @post.each do |post|%>
  <% if post.image.present?%>

    <h1> <%= link_to post.title, post %></h1><br>

    <%= image_tag post.image.url(:thumb)%>

    <%= simple_format post.content %>
    <hr color="blue" >
  <% else %>

    <h1> <%= link_to post.title, post %></h1><br>
    <%= simple_format post.content %>
    <hr color="blue">

  <% end %>

<% end %>