Skip to content

Commit

Permalink
Commit 3. - Finished I1 of tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisJov committed Aug 4, 2017
1 parent 70bc9ca commit 61141c7
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 23 deletions.
135 changes: 114 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions app/controllers/articles_controller.rb
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
5 changes: 5 additions & 0 deletions app/helpers/articles_helper.rb
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
18 changes: 18 additions & 0 deletions app/views/articles/_form.html.erb
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 %>
2 changes: 2 additions & 0 deletions app/views/articles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Edit your article</h1>
<%= render partial: 'form' %>
2 changes: 2 additions & 0 deletions app/views/articles/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Create a new article</h1>
<%= render partial: 'form' %>
5 changes: 4 additions & 1 deletion app/views/articles/show.html.erb
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 %>
4 changes: 3 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</head>

<body>
<%= yield %>
<p class="flash"><%= flash.notice %></p>

<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions config/routes.rb
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

0 comments on commit 61141c7

Please sign in to comment.