Brief question, beginner’s work on Ruby/Rails. Here’s my view:
<h1>News</h1>
<%= @posts.each do |post| %>
<h1><%= post.title %></h1>
<p><strong>By:</strong> <%= post.name %></p>
<p><%= post.content %></p>
<p><%= link_to 'Read More', post %> | <%= link_to 'Edit', edit_post_path(post) %> | <%= link_to 'Destroy', post, :confirm => 'Are you sure you want to delete this post?', :method => :delete %></p>
<p>hello!</p>
<% end %>
<br />
<%= link_to 'New Post', new_post_path %>
I put the <p>hello<p> in there so I could see where the output was coming from, but here’s what the page looks like…
News
sdfsfsdfsdf
By: sdf
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a risus eros, sed malesuada lectus. Ut faucibus urna vel risus mollis et pulvinar augue gravida. Nunc ultricies viverra tellus…
Read More | Edit | Destroy
hello!
[#<Post id: 5, name: "sdf", title: "sdfsfsdfsdf", content: "Lorem ipsum dolor sit amet, consectetur adipiscing ...", created_at: "2010-09-28 22:43:57", updated_at: "2010-09-28 22:43:57">]
New Post
That last dump, which looks like XML or a JSON object, following the loop, is not being told to print anywhere in the view…I don’t understand where it’s coming from, what it’s called, or how to get rid of it. Help?
Wild guess: change
<%= @posts.each do |post| %>to<% @posts.each do |post| %>(notice lack of=sign).<% .. %>in erb template means “execute this”.<%= .. %>in erb template means “execute this and print output on the page”.@posts.eachis a loop. It’s used to iterate over@postscollection. And even thougheachmethod returns some data (collection itself), there’s no need to print that data.