Skip to content

Commit 9909f9c

Browse files
author
github_username
committed
Initial commit
1 parent 3ef6668 commit 9909f9c

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed
+32-29
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
11
class ArticlesController < ApplicationController
22
def index
33
@articles = Article.all
4-
end
4+
end
55

6-
def show
7-
@article = Article.find(params[:id])
8-
end
6+
def show
7+
@article = Article.find(params[:id])
8+
end
99

10-
def new
11-
@article = Article.new
12-
end
10+
def new
11+
@article = Article.new
12+
end
1313

14-
def create
15-
@article = Article.new(title: "...", body: "...")
14+
def create
15+
@article = Article.new(article_params)
1616

17-
if @article.save
18-
redirect_to @article
19-
else
20-
render :new, status: :unprocessable_entity
21-
end
17+
if @article.save
18+
redirect_to @article
19+
else
20+
render :new, status: :unprocessable_entity
21+
end
2222
end
23+
2324
def edit
2425
@article = Article.find(params[:id])
2526
end
26-
def update
27-
@article = Article.find(params[:id])
28-
if @article.update(article_params)
29-
redirect_to @article
30-
else
31-
render :edit, status: :unprocessable_entity
32-
end
33-
end
3427

35-
def destroy
36-
@article = Article.find(params[:id])
37-
@article.destroy
28+
def update
29+
@article = Article.find(params[:id])
3830

39-
redirect_to root_path, status: see_other
31+
if @article.update(article_params)
32+
redirect_to @article
33+
else
34+
render :edit, status: :unprocessable_entity
4035
end
36+
end
37+
38+
def destroy
39+
@article = Article.find(params[:id])
40+
@article.destroy
4141

42-
private
42+
redirect_to root_path, status: :see_other
43+
end
44+
45+
private
4346
def article_params
4447
params.require(:article).permit(:title, :body)
45-
end
46-
end
48+
end
49+
end
+10-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
class CommentsController < ApplicationController
2-
def create
3-
@article = Article.find(params[:article_id])
4-
@comment = @article.comments.create(comment.params)
5-
redirect_to article_path(@article)
6-
end
7-
private
8-
def comment_params
9-
params.require(:comment).permit(:commenter, :body)
10-
end
2+
def create
3+
@article = Article.find(params[:article_id])
4+
@comment = @article.comments.create(comment_params)
5+
redirect_to article_path(@article)
6+
end
7+
8+
private
9+
def comment_params
10+
params.require(:comment).permit(:commenter, :body)
11+
end
1112
end

app/views/articles/show.html.erb

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
</ul>
1212

1313
<h2>Comments</h2>
14-
<%= render @article.comments %>
15-
16-
14+
<%= puts @article.comments %>
1715
<h2>Add a comment:</h2>
18-
<%= render 'comments/form' %>
16+
<%= render 'comments/form' %>

0 commit comments

Comments
 (0)