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:
parent
47ec49276d
commit
323d2c42c3
4 changed files with 34 additions and 77 deletions
|
@ -1,10 +1,10 @@
|
||||||
<p>
|
<p>
|
||||||
<b>Commenter:</b>
|
<strong>Commenter:</strong>
|
||||||
<%= comment.commenter %>
|
<%= comment.commenter %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Comment:</b>
|
<strong>Comment:</strong>
|
||||||
<%= comment.body %>
|
<%= comment.body %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<%= form_for([@post, @post.comments.build]) do |f| %>
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
||||||
<div class="field">
|
<p>
|
||||||
<%= f.label :commenter %><br />
|
<%= f.label :commenter %><br />
|
||||||
<%= f.text_field :commenter %>
|
<%= f.text_field :commenter %>
|
||||||
</div>
|
</p>
|
||||||
<div class="field">
|
<p>
|
||||||
<%= f.label :body %><br />
|
<%= f.label :body %><br />
|
||||||
<%= f.text_area :body %>
|
<%= f.text_area :body %>
|
||||||
</div>
|
</p>
|
||||||
<div class="actions">
|
<p>
|
||||||
<%= f.submit %>
|
<%= f.submit %>
|
||||||
</div>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -9,32 +9,10 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>Comments</h2>
|
<h2>Comments</h2>
|
||||||
<% @post.comments.each do |comment| %>
|
<%= render @post.comments %>
|
||||||
<p>
|
|
||||||
<strong>Commenter:</strong>
|
|
||||||
<%= comment.commenter %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Comment:</strong>
|
|
||||||
<%= comment.body %>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<h2>Add a comment:</h2>
|
<h2>Add a comment:</h2>
|
||||||
<%= form_for([@post, @post.comments.build]) do |f| %>
|
<%= render "comments/form" %>
|
||||||
<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 %>
|
|
||||||
|
|
||||||
<%= link_to 'Edit Post', edit_post_path(@post) %> |
|
<%= link_to 'Edit Post', edit_post_path(@post) %> |
|
||||||
<%= link_to 'Back to Posts', posts_path %>
|
<%= link_to 'Back to Posts', posts_path %>
|
||||||
|
|
|
@ -1428,12 +1428,12 @@ following into it:
|
||||||
|
|
||||||
<erb>
|
<erb>
|
||||||
<p>
|
<p>
|
||||||
<b>Commenter:</b>
|
<strong>Commenter:</strong>
|
||||||
<%= comment.commenter %>
|
<%= comment.commenter %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Comment:</b>
|
<strong>Comment:</strong>
|
||||||
<%= comment.body %>
|
<%= comment.body %>
|
||||||
</p>
|
</p>
|
||||||
</erb>
|
</erb>
|
||||||
|
@ -1442,21 +1442,14 @@ Then you can change +app/views/posts/show.html.erb+ to look like the
|
||||||
following:
|
following:
|
||||||
|
|
||||||
<erb>
|
<erb>
|
||||||
<p id="notice"><%= notice %></p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Name:</b>
|
<strong>Title:</strong>
|
||||||
<%= @post.name %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<b>Title:</b>
|
|
||||||
<%= @post.title %>
|
<%= @post.title %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Content:</b>
|
<strong>Text:</strong>
|
||||||
<%= @post.content %>
|
<%= @post.texthttp://beginningruby.org/ %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>Comments</h2>
|
<h2>Comments</h2>
|
||||||
|
@ -1464,23 +1457,21 @@ following:
|
||||||
|
|
||||||
<h2>Add a comment:</h2>
|
<h2>Add a comment:</h2>
|
||||||
<%= form_for([@post, @post.comments.build]) do |f| %>
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
||||||
<div class="field">
|
<p>
|
||||||
<%= f.label :commenter %><br />
|
<%= f.label :commenter %><br />
|
||||||
<%= f.text_field :commenter %>
|
<%= f.text_field :commenter %>
|
||||||
</div>
|
</p>
|
||||||
<div class="field">
|
<p>
|
||||||
<%= f.label :body %><br />
|
<%= f.label :body %><br />
|
||||||
<%= f.text_area :body %>
|
<%= f.text_area :body %>
|
||||||
</div>
|
</p>
|
||||||
<div class="actions">
|
<p>
|
||||||
<%= f.submit %>
|
<%= f.submit %>
|
||||||
</div>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<br />
|
|
||||||
|
|
||||||
<%= link_to 'Edit Post', edit_post_path(@post) %> |
|
<%= link_to 'Edit Post', edit_post_path(@post) %> |
|
||||||
<%= link_to 'Back to Posts', posts_path %> |
|
<%= link_to 'Back to Posts', posts_path %>
|
||||||
</erb>
|
</erb>
|
||||||
|
|
||||||
This will now render the partial in +app/views/comments/_comment.html.erb+ once
|
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>
|
<erb>
|
||||||
<%= form_for([@post, @post.comments.build]) do |f| %>
|
<%= form_for([@post, @post.comments.build]) do |f| %>
|
||||||
<div class="field">
|
<p>
|
||||||
<%= f.label :commenter %><br />
|
<%= f.label :commenter %><br />
|
||||||
<%= f.text_field :commenter %>
|
<%= f.text_field :commenter %>
|
||||||
</div>
|
</p>
|
||||||
<div class="field">
|
<p>
|
||||||
<%= f.label :body %><br />
|
<%= f.label :body %><br />
|
||||||
<%= f.text_area :body %>
|
<%= f.text_area :body %>
|
||||||
</div>
|
</p>
|
||||||
<div class="actions">
|
<p>
|
||||||
<%= f.submit %>
|
<%= f.submit %>
|
||||||
</div>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</erb>
|
</erb>
|
||||||
|
|
||||||
Then you make the +app/views/posts/show.html.erb+ look like the following:
|
Then you make the +app/views/posts/show.html.erb+ look like the following:
|
||||||
|
|
||||||
<erb>
|
<erb>
|
||||||
<p id="notice"><%= notice %></p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Name:</b>
|
<strong>Title:</strong>
|
||||||
<%= @post.name %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<b>Title:</b>
|
|
||||||
<%= @post.title %>
|
<%= @post.title %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Content:</b>
|
<strong>Text:</strong>
|
||||||
<%= @post.content %>
|
<%= @post.texthttp://beginningruby.org/ %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2>Comments</h2>
|
|
||||||
<%= render @post.comments %>
|
|
||||||
|
|
||||||
<h2>Add a comment:</h2>
|
<h2>Add a comment:</h2>
|
||||||
<%= render "comments/form" %>
|
<%= render "comments/form" %>
|
||||||
|
|
||||||
<br />
|
|
||||||
|
|
||||||
<%= link_to 'Edit Post', edit_post_path(@post) %> |
|
<%= link_to 'Edit Post', edit_post_path(@post) %> |
|
||||||
<%= link_to 'Back to Posts', posts_path %> |
|
<%= link_to 'Back to Posts', posts_path %>
|
||||||
</erb>
|
</erb>
|
||||||
|
|
||||||
The second render just defines the partial template we want to render,
|
The second render just defines the partial template we want to render,
|
||||||
|
|
Loading…
Reference in a new issue