File tree 3 files changed +44
-42
lines changed
3 files changed +44
-42
lines changed Original file line number Diff line number Diff line change 1
1
class ArticlesController < ApplicationController
2
2
def index
3
3
@articles = Article . all
4
- end
4
+ end
5
5
6
- def show
7
- @article = Article . find ( params [ :id ] )
8
- end
6
+ def show
7
+ @article = Article . find ( params [ :id ] )
8
+ end
9
9
10
- def new
11
- @article = Article . new
12
- end
10
+ def new
11
+ @article = Article . new
12
+ end
13
13
14
- def create
15
- @article = Article . new ( title : "..." , body : "..." )
14
+ def create
15
+ @article = Article . new ( article_params )
16
16
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
22
22
end
23
+
23
24
def edit
24
25
@article = Article . find ( params [ :id ] )
25
26
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
34
27
35
- def destroy
36
- @article = Article . find ( params [ :id ] )
37
- @article . destroy
28
+ def update
29
+ @article = Article . find ( params [ :id ] )
38
30
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
40
35
end
36
+ end
37
+
38
+ def destroy
39
+ @article = Article . find ( params [ :id ] )
40
+ @article . destroy
41
41
42
- private
42
+ redirect_to root_path , status : :see_other
43
+ end
44
+
45
+ private
43
46
def article_params
44
47
params . require ( :article ) . permit ( :title , :body )
45
- end
46
- end
48
+ end
49
+ end
Original file line number Diff line number Diff line change 1
1
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
11
12
end
Original file line number Diff line number Diff line change 11
11
</ ul >
12
12
13
13
< h2 > Comments</ h2 >
14
- <%= render @article . comments %>
15
-
16
-
14
+ <%= puts @article . comments %>
17
15
< h2 > Add a comment:</ h2 >
18
- <%= render 'comments/form' %>
16
+ <%= render 'comments/form' %>
You can’t perform that action at this time.
0 commit comments