質問編集履歴
2
controllerの記述を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
### 該当のソースコード
|
13
13
|
|
14
14
|
```ruby
|
15
|
+
index.html.haml
|
15
16
|
.Topic
|
16
17
|
.Topic__Top
|
17
18
|
= link_to new_post_path class: 'Topic__New' do
|
@@ -25,6 +26,46 @@
|
|
25
26
|
= post.content
|
26
27
|
```
|
27
28
|
|
29
|
+
```ruby
|
30
|
+
psots_controller.rb
|
31
|
+
|
32
|
+
class PostsController < ApplicationController
|
33
|
+
before_action :move_to_index, except: [:index, :show]
|
34
|
+
def index
|
35
|
+
@posts = Post.all
|
36
|
+
end
|
37
|
+
|
38
|
+
def new
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def create
|
43
|
+
Post.create(post_params)
|
44
|
+
end
|
45
|
+
|
46
|
+
def show
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def post_params
|
52
|
+
params.require(:post).parmit(:content, :title, :image).merge(user_id current_user.id)
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_post
|
56
|
+
@post = Post.find(params[:id])
|
57
|
+
end
|
58
|
+
|
59
|
+
def move_to_index
|
60
|
+
unless user_signed_in?
|
61
|
+
redirect_to action: :index
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
```
|
68
|
+
|
28
69
|
### 試したこと
|
29
70
|
##コントローラー修正
|
30
71
|
初めはpostsコントローラーでない別のコントローラーのエラーだったので修正し、上記エラー文になりました。
|
1
補足情報の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
- @posts.each do |post|
|
21
21
|
.Topic__Row
|
22
22
|
= post.title
|
23
|
-
|
23
|
+
= link_to post_path
|
24
24
|
.Topic__Row
|
25
25
|
= post.content
|
26
26
|
```
|
@@ -34,4 +34,5 @@
|
|
34
34
|
|
35
35
|
### 補足情報(FW/ツールのバージョンなど)
|
36
36
|
|
37
|
-
|
37
|
+
ユーザーを投稿内容に結び付けるためdeviseを導入しています。
|
38
|
+
また詳細に確認していくと**= link_to post_pathでエラーが起きてしまいますしリンク先のビューも用意しています。
|