Reputation:
I am trying to create a simple Ruby on Rails index page using a table. My intention is to have the page include a HTML table that displays items from the model in each row. The model is called "Post", and it contains four attributes - Department, Professor, Course, and Title.
The problem is, the Table is displayed in a peculiar way as shown in the screenshot of the application at this link: https://i.sstatic.net/OkE6M.png.
There is a huge chunk of nonsense texts displaying right above the table. The table itself is being rendered as intended, but I do not understand why the unnecessary text chunk is being displayed. There is no error message when I run the application. The rest of the application is displayed properly and functional.
The source code of the view of the page looks like this:
index.html.erb
<% provide(:title, 'All posts') %>
<h1>All posts</h1>
<table>
<thead>
<tr>
<th>Department</th>
<th>Professor</th>
<th>Course</th>
<th>Title</th>
</tr>s
</thead>
<tbody>
<%= @posts.each do |post| %>
<tr>
<td><%= post.department %></td>
<td><%= post.professor %></td>
<td><%= post.course %></td>
<td><%= link_to post.title, post%></td>
</tr>
<% end %>
</tbody>
</table>
Upon inspecting the source of the rendered page, I found out that the block of the problematic text is included within the table group. Below is a partial excerpt from the rendered HTML:
* .....more code above *
<tr>
<td>Quod sed ex fuga nemo.</td>
<td>Isabel Douglas III</td>
<td>Sint qui natus nesciunt.</td>
<td><a href="/posts/2">Qui aperiam voluptas alias molestias nisi.</a></td>
</tr>
<tr>
<td>Quod sed ex fuga nemo.</td>
<td>Isabel Douglas III</td>
<td>Sint qui natus nesciunt.</td>
<td><a href="/posts/1">Qui aperiam voluptas alias molestias nisi.</a></td>
</tr>
[#<Post id: 60, department: "Consequatur voluptatem.", professor: "Humberto Wisozk", course: "Suscipit rerum possimus culpa aut et.", content: "Beatae minima aut est eos.", user_id: 6, created_at: "2014-01-14 20:15:11", updated_at: "2014-01-14 20:15:11", title: "Sed quia.">, #<Post id: 59, department: "Consequatur voluptatem.", professor: "Humberto Wisozk", course: "Suscipit rerum possimus culpa aut et.", content: "Beatae minima aut est eos.", user_id: 5, created_at: "2014-01-14 20:15:11", updated_at: "2014-01-14 20:15:11", title: "Sed quia.">, #<Post id: 58, department: "Consequatur voluptatem.", professor: "Humberto Wisozk", course: "Suscipit rerum possimus culpa aut et.", content: "Beatae minima aut est eos.", user_id: 4, created_at: "2014-01-14 20:15:11", updated_at: "2014-01-14 20:15:11", title: "Sed quia.">, #<Post id: 57, department: "Consequatur voluptatem.", professor: "Humberto Wisozk", course: "Suscipit rerum possimus culpa aut et.", content: "Beatae minima aut est eos.", user_id: 3, created_at: "2014-01-14 20:15:11", updated_at: "2014-01-14 20:15:11", title: "Sed quia.">, #<Post id: 56, department: "Consequatur voluptatem.", professor: "Humberto Wisozk", course: "Suscipit rerum possimus culpa aut et.", content: "Beatae minima aut est eos.", user_id: 2, created_at: "2014-01-14 20:15:11", updated_at: "2014-01-14 20:15:11", title: "Sed quia.">, #<] </tbody>
</table>
* more code below.... *
Below is the Gemfile used for the application:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.1'
gem 'pg', '0.15.1'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.1.2'
gem "simple_form"
gem 'faker', '1.1.2' # allow us to make sample users
gem 'will_paginate', '3.0.4' # pagination method
gem 'bootstrap-will_paginate', '0.0.9' # configures will_paginate to use Bootstrap's style
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
gem 'factory_girl_rails', '4.2.1'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
Why is this happening?
Upvotes: 0
Views: 679
Reputation: 5343
Take out the =
in <%= @posts.each do |post| %>
.
array.each{}
returns the array, for chaining
Upvotes: 1