質問編集履歴
1
コード内容の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,21 +1,215 @@
|
|
1
|
+
rails入門書を見ながらメッセージボードを作っています。
|
2
|
+
|
3
|
+
「NoMethod 」エラーが出てしまいました。
|
4
|
+
|
5
|
+
### エラー内容
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```ここに言語を入力
|
10
|
+
|
1
11
|
NoMethodError in BoardMessagesController#index
|
2
12
|
|
3
|
-
undefined method `authenticate_account!' for #<BoardMessagesController:0x00007ff175
|
13
|
+
undefined method `authenticate_account!' for #<BoardMessagesController:0x00007ff175d69ef8> Did you mean? authenticate_with_http_basic
|
4
|
-
|
5
|
-
|
6
|
-
|
14
|
+
|
7
|
-
|
15
|
+
Extracted source (around line #428):
|
16
|
+
|
8
|
-
|
17
|
+
426
|
18
|
+
|
9
|
-
|
19
|
+
427
|
20
|
+
|
10
|
-
|
21
|
+
428
|
22
|
+
|
23
|
+
429
|
24
|
+
|
25
|
+
430
|
26
|
+
|
27
|
+
431
|
28
|
+
|
29
|
+
|
30
|
+
|
11
|
-
lambda do |target, value, &block|
|
31
|
+
lambda do |target, value, &block|
|
12
|
-
|
32
|
+
|
13
|
-
target, block, method, *arguments = expand(target,
|
33
|
+
target, block, method, *arguments = expand(target, value, block)
|
14
|
-
|
15
|
-
value, block)
|
16
34
|
|
17
35
|
target.send(method, *arguments, &block)
|
18
36
|
|
19
37
|
end
|
20
38
|
|
21
39
|
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
メソッドが定義されていないというのはわかりました。
|
46
|
+
|
47
|
+
しかし、具体的にどうコードを書きなおせば良いのかわかりません。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
### コントローラー内容
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```ここに言語を入力
|
56
|
+
|
57
|
+
class BoardMessagesController < ApplicationController
|
58
|
+
|
59
|
+
before_action :set_board_message, only: [:show, :edit, :update, :destroy]
|
60
|
+
|
61
|
+
before_action :authenticate_account!
|
62
|
+
|
63
|
+
layout 'board_message'
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# GET /board_messages
|
68
|
+
|
69
|
+
# GET /board_messages.json
|
70
|
+
|
71
|
+
def index
|
72
|
+
|
73
|
+
@board_messages = BoardMessage.page(params[:page]).order('created_at desc')
|
74
|
+
|
75
|
+
users = BoardUser.where('account_id == ?', current_account.id)[0]
|
76
|
+
|
77
|
+
if users == nil then
|
78
|
+
|
79
|
+
user = BoardUser.new
|
80
|
+
|
81
|
+
user.account_id = current_accunt.id
|
82
|
+
|
83
|
+
user.nickname = '<<no name>>'
|
84
|
+
|
85
|
+
user.save
|
86
|
+
|
87
|
+
users = BoardUser.where 'account_id == ?', current_account.id
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
@board_user = users
|
92
|
+
|
93
|
+
@board_message = BoardMessage.new
|
94
|
+
|
95
|
+
@board_message.board_user_id = @board_user_id
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# GET /board_messages/1
|
102
|
+
|
103
|
+
# GET /board_messages/1.json
|
104
|
+
|
105
|
+
def show
|
106
|
+
|
107
|
+
redirect_to '/board_messages'
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
# GET /board_messages/new
|
114
|
+
|
115
|
+
def new
|
116
|
+
|
117
|
+
redirect_to '/board_messages'
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# GET /board_messages/1/edit
|
124
|
+
|
125
|
+
def edit
|
126
|
+
|
127
|
+
redirect_to '/board_messages'
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
# POST /board_messages
|
134
|
+
|
135
|
+
# POST /board_messages.json
|
136
|
+
|
137
|
+
def create
|
138
|
+
|
139
|
+
@board_message = BoardMessage.page(params[:page]).order('created_at desc')
|
140
|
+
|
141
|
+
@board_message = BoardMessage.new(board_message_params)
|
142
|
+
|
143
|
+
@board_user = BoardUser.where('account_id == ?', current_account.id)[0]
|
144
|
+
|
145
|
+
respond_to do |format|
|
146
|
+
|
147
|
+
if @board_message.save
|
148
|
+
|
149
|
+
format.html { redirect_to '/board_messages' }
|
150
|
+
|
151
|
+
format.json { render :show, status: :created, location: @board_message }
|
152
|
+
|
153
|
+
else
|
154
|
+
|
155
|
+
format.html { render :index }
|
156
|
+
|
157
|
+
format.json { render json: @board_message.errors, status: :unprocessable_entity }
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
# PATCH/PUT /board_messages/1
|
168
|
+
|
169
|
+
# PATCH/PUT /board_messages/1.json
|
170
|
+
|
171
|
+
def update
|
172
|
+
|
173
|
+
redirect_to '/board_messages'
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
# DELETE /board_messages/1
|
180
|
+
|
181
|
+
# DELETE /board_messages/1.json
|
182
|
+
|
183
|
+
def destroy
|
184
|
+
|
185
|
+
redirect_to '/board_messages'
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
private
|
192
|
+
|
193
|
+
# Use callbacks to share common setup or constraints between actions.
|
194
|
+
|
195
|
+
def set_board_message
|
196
|
+
|
197
|
+
@board_message = BoardMessage.find(params[:id])
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
# Only allow a list of trusted parameters through.
|
204
|
+
|
205
|
+
def board_message_params
|
206
|
+
|
207
|
+
params.require(:board_message).permit(:content, :board_user_id)
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
```
|