1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rewrite refactoring section in getting started guide

This commit is contained in:
Oscar Del Ben 2012-05-02 11:13:20 +02:00
parent 47ec49276d
commit 323d2c42c3
4 changed files with 34 additions and 77 deletions

View file

@ -1,13 +1,13 @@
<p>
<b>Commenter:</b>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<b>Comment:</b>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<p>
<%= link_to 'Destroy Comment', [comment.post, comment],
:confirm => 'Are you sure?',

View file

@ -1,13 +1,13 @@
<%= 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 %>

View file

@ -9,32 +9,10 @@
</p>
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<% end %>
<%= render @post.comments %>
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>
<p>
<%= f.label :commenter %><br />
<%= f.text_field :commenter %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<%= render "comments/form" %>
<%= link_to 'Edit Post', edit_post_path(@post) %> |
<%= link_to 'Back to Posts', posts_path %>

View file

@ -1428,12 +1428,12 @@ following into it:
<erb>
<p>
<b>Commenter:</b>
<strong>Commenter:</strong>
<%= comment.commenter %>
</p>
<p>
<b>Comment:</b>
<strong>Comment:</strong>
<%= comment.body %>
</p>
</erb>
@ -1442,21 +1442,14 @@ Then you can change +app/views/posts/show.html.erb+ to look like the
following:
<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>
@ -1464,23 +1457,21 @@ following:
<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>
This will now render the partial in +app/views/comments/_comment.html.erb+ once
@ -1496,50 +1487,38 @@ create a file +app/views/comments/_form.html.erb+ containing:
<erb>
<%= 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 %>
</erb>
Then you make the +app/views/posts/show.html.erb+ look like the following:
<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>
<%= render @post.comments %>
<h2>Add a comment:</h2>
<%= render "comments/form" %>
<br />
<%= link_to 'Edit Post', edit_post_path(@post) %> |
<%= link_to 'Back to Posts', posts_path %> |
<%= link_to 'Back to Posts', posts_path %>
</erb>
The second render just defines the partial template we want to render,