-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the edit and update methods in the ArticlesController to allow for editing and updating an existing article in the application using the edit_article_path (articles/:id/edit) and a form in the created edit.html.erb view file. Refactor the form shared between the new and edit actions into a partial that both views render. * Add edit and update actions to ArticlesController * Add tests for edit and update in ArticlesControllerTest * Refactor new and edit form into _form.html.erb partial * Refactor repeated code in ArticlesControllerTest Completes Rails Getting Started Guide: * 7 CRUDit Where CRUDit Is Due * 7.4 Updating an Article * 7.4.1 Using Partials to Share View Code * 7.4.2 Finishing Up
- Loading branch information
1 parent
3d76b4b
commit eb49741
Showing
6 changed files
with
100 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<%= form_with model: article do |form| %> | ||
<div> | ||
<%= form.label :title %><br> | ||
<%= form.text_field :title %> | ||
<% article.errors.full_messages_for(:title).each do |message| %> | ||
<div class="error"><%= message %></div> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :body %><br> | ||
<%= form.text_area :body %><br> | ||
<% article.errors.full_messages_for(:body).each do |message| %> | ||
<div class="error"><%= message %></div> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>Edit Article</h1> | ||
|
||
<%= render "form", article: @article %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
<h1>New Article</h1> | ||
|
||
<%= form_with model: @article do |form| %> | ||
<div> | ||
<%= form.label :title %><br> | ||
<%= form.text_field :title %> | ||
<% @article.errors.full_messages_for(:title).each do |message| %> | ||
<div class="error"><%= message %></div> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :body %><br> | ||
<%= form.text_area :body %> | ||
<% @article.errors.full_messages_for(:body).each do |message| %> | ||
<div class="error"><%= message %></div> | ||
<% end %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> | ||
<%= render "form", article: @article %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<h1><%= @article.title %></h1> | ||
|
||
<p><%= @article.body %></p> | ||
|
||
<ul> | ||
<li><%= link_to "Edit", edit_article_path(@article) %></li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters