回答編集履歴
2
追記
test
CHANGED
@@ -15,3 +15,67 @@
|
|
15
15
|
# ^^^^^^^^^^^^
|
16
16
|
|
17
17
|
```
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
> ```ruby
|
22
|
+
|
23
|
+
# post_controller
|
24
|
+
|
25
|
+
def create
|
26
|
+
|
27
|
+
@post = Post.new(
|
28
|
+
|
29
|
+
params[:post].permit(:topic_id, :name, :seats, :rating, :body))
|
30
|
+
|
31
|
+
if @post.save
|
32
|
+
|
33
|
+
redirect_to topics_show_path(params[:post]['topic_id'])
|
34
|
+
|
35
|
+
else
|
36
|
+
|
37
|
+
render("topics/show")
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
> ```
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
|
49
|
+
# posts_controller
|
50
|
+
|
51
|
+
# ^^^^^^^^^^^^^^^^
|
52
|
+
|
53
|
+
def create
|
54
|
+
|
55
|
+
@post = Post.new(
|
56
|
+
|
57
|
+
params[:post].permit(:topic_id, :name, :seats, :rating, :body))
|
58
|
+
|
59
|
+
if @post.save
|
60
|
+
|
61
|
+
redirect_to topics_show_path(params[:post]['topic_id'])
|
62
|
+
|
63
|
+
else
|
64
|
+
|
65
|
+
+ @topic = ...
|
66
|
+
|
67
|
+
+ @newpost = ...
|
68
|
+
|
69
|
+
+ @posts = ...
|
70
|
+
|
71
|
+
render("topics/show/#{@topic.id}")
|
72
|
+
|
73
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```
|
1
ファイル名追加
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
> ```ruby
|
2
|
+
|
3
|
+
# routes.rb
|
2
4
|
|
3
5
|
post "posts/create" => "post#create", as: :post_create
|
4
6
|
|