Rewrite comments action in getting started guide

This commit is contained in:
Oscar Del Ben 2012-05-02 10:42:59 +02:00
parent a411e8828a
commit 47ec49276d
3 changed files with 26 additions and 21 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -8,6 +8,18 @@
<%= @post.text %>
</p>
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<% end %>
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>

View File

@ -1367,60 +1367,53 @@ template. This is where we want the comment to show, so let's add that to the
+app/views/posts/show.html.erb+.
<erb>
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @post.name %>
</p>
<p>
<b>Title:</b>
<strong>Title:</strong>
<%= @post.title %>
</p>
<p>
<b>Content:</b>
<%= @post.content %>
<strong>Text:</strong>
<%= @post.texthttp://beginningruby.org/ %>
</p>
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p>
<b>Commenter:</b>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<b>Comment:</b>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<% end %>
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>
<div class="field">
<p>
<%= f.label :commenter %><br />
<%= f.text_field :commenter %>
</div>
<div class="field">
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</div>
<div class="actions">
</p>
<p>
<%= f.submit %>
</div>
</p>
<% end %>
<br />
<%= link_to 'Edit Post', edit_post_path(@post) %> |
<%= link_to 'Back to Posts', posts_path %> |
<%= link_to 'Back to Posts', posts_path %>
</erb>
Now you can add posts and comments to your blog and have them show up in the
right places.
!images/getting_started/post_with_comments.png(Post with Comments)!
h3. Refactoring
Now that we have posts and comments working, take a look at the