-
-
+
+
diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb
index 42dc8e0..65e7328 100644
--- a/app/controllers/articles_controller.rb
+++ b/app/controllers/articles_controller.rb
@@ -1,4 +1,6 @@
class ArticlesController < ApplicationController
+ include ArticlesHelper
+
def index
@articles = Article.all
end
@@ -6,4 +8,34 @@ def index
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
diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb
index 2968277..35703ec 100644
--- a/app/helpers/articles_helper.rb
+++ b/app/helpers/articles_helper.rb
@@ -1,2 +1,7 @@
module ArticlesHelper
+
+ def article_params
+ params.require(:article).permit(:title, :body)
+ end
+
end
diff --git a/app/views/articles/_form.html.erb b/app/views/articles/_form.html.erb
new file mode 100644
index 0000000..93017c3
--- /dev/null
+++ b/app/views/articles/_form.html.erb
@@ -0,0 +1,18 @@
+<%= form_for(@article) do |f| %>
+
+ <% @article.errors.full_messages.each do |error| %>
+ - <%= error %>
+ <% end %>
+
+
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+
+
+ <%= f.label :body %>
+ <%= f.text_area :body %>
+
+
+ <%= f.submit %>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/articles/edit.html.erb b/app/views/articles/edit.html.erb
new file mode 100644
index 0000000..9908e20
--- /dev/null
+++ b/app/views/articles/edit.html.erb
@@ -0,0 +1,2 @@
+Edit your article
+<%= render partial: 'form' %>
\ No newline at end of file
diff --git a/app/views/articles/new.html.erb b/app/views/articles/new.html.erb
new file mode 100644
index 0000000..4b5cc9c
--- /dev/null
+++ b/app/views/articles/new.html.erb
@@ -0,0 +1,2 @@
+Create a new article
+<%= render partial: 'form' %>
\ No newline at end of file
diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb
index 058bb74..bb44324 100644
--- a/app/views/articles/show.html.erb
+++ b/app/views/articles/show.html.erb
@@ -1,3 +1,6 @@
<%= @article.title %>
<%= @article.body %>
-<%= 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 %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index b55f0a5..1e87981 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -9,6 +9,8 @@
- <%= yield %>
+ <%= flash.notice %>
+
+ <%= yield %>