2015-04-04 31 views
0
靜態頁面

在我的應用程序時,我在我的靜態頁面渲染家Post.all我得到像這樣的代碼在頁面如何刪除節點下方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>]
結束

如何刪除或停止獲取?

,這裏是我的Gemfile

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]

在頁面控制器家裏動作我已經把@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

你應該在第一循環<%= @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 %> 
+1

擴大刪除=。 %=將顯示評估內容。只是%只會評估 – Austio 2015-04-04 02:51:01

+0

非常感謝。我很新的rails基本語法錯誤也會發生。非常感謝您的幫助。 – 2015-04-04 02:54:32

+0

不要擔心每個未來的專家將不得不作爲初學者開始:)。不要忘記投票答案。 btw Austio添加一個你應該知道'='的好點 – 2015-04-04 03:03:33