-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
181 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 +1,41 @@ | ||
class ArticlesController < ApplicationController | ||
include ArticlesHelper | ||
|
||
def index | ||
@articles = Article.all | ||
end | ||
|
||
def show | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
def new | ||
@article = Article.new | ||
end | ||
|
||
def create | ||
@article = Article.new(article_params) | ||
@article.save | ||
|
||
redirect_to article_path(@article) | ||
end | ||
|
||
def edit | ||
@article = Article.find(params[:id]) | ||
end | ||
|
||
def update | ||
@article = Article.find(params[:id]) | ||
@article.update(article_params) | ||
|
||
redirect_to article_path(@article) | ||
end | ||
|
||
def destroy | ||
@article = Article.find(params[:id]) | ||
@article.destroy | ||
|
||
redirect_to articles_path | ||
end | ||
|
||
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
module ArticlesHelper | ||
|
||
def article_params | ||
params.require(:article).permit(:title, :body) | ||
end | ||
|
||
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,18 @@ | ||
<%= form_for(@article) do |f| %> | ||
<ul> | ||
<% @article.errors.full_messages.each do |error| %> | ||
<li> <%= error %> </li> | ||
<% end %> | ||
</ul> | ||
<p> | ||
<%= f.label :title %> <br /> | ||
<%= f.text_field :title %> | ||
</p> | ||
<p> | ||
<%= f.label :body %> <br /> | ||
<%= f.text_area :body %> | ||
</p> | ||
<p> | ||
<%= f.submit %> | ||
</p> | ||
<% 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,2 @@ | ||
<h1>Edit your article</h1> | ||
<%= render partial: 'form' %> |
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,2 @@ | ||
<h1>Create a new article</h1> | ||
<%= render partial: 'form' %> |
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,6 @@ | ||
<h1><%= @article.title %></h1> | ||
<p><%= @article.body %></p> | ||
<%= link_to "<< Back to Articles List", articles_path %> | ||
|
||
<%= link_to 'Edit Article', edit_article_path(@article) %> | ||
<%= link_to 'Delete Article', article_path(@article), method: :delete, data: {confirm: 'Are you sure it is wise to delete the article?'} %> | ||
<%= link_to '<< Back to Articles List', articles_path %> |
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
</head> | ||
|
||
<body> | ||
<%= yield %> | ||
<p class="flash"><%= flash.notice %></p> | ||
|
||
<%= yield %> | ||
</body> | ||
</html> |
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,4 +1,5 @@ | ||
Rails.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
root to: 'articles#index' | ||
resources :articles | ||
end |