質問編集履歴
9
エラーの対処法があっているのかの確認
title
CHANGED
File without changes
|
body
CHANGED
@@ -383,4 +383,10 @@
|
|
383
383
|
|
384
384
|
質問ばっかりすいません。
|
385
385
|
|
386
|
-
よろしくお願いします。
|
386
|
+
よろしくお願いします。
|
387
|
+
|
388
|
+
追記⑥
|
389
|
+

|
390
|
+
|
391
|
+
qiitaやteratailsで探したのですがgemfileの更新などが出てきました。
|
392
|
+
やっていいものかわからなかったので確認のため質問します。
|
8
現場を再度アップします。
title
CHANGED
File without changes
|
body
CHANGED
@@ -308,4 +308,79 @@
|
|
308
308
|
これでいいのですか?
|
309
309
|
|
310
310
|
以下のエラーになりました。
|
311
|
-

|
311
|
+

|
312
|
+
|
313
|
+
|
314
|
+
追記⑤
|
315
|
+
|
316
|
+
like ?"."#{month}%"がカンマの部分を直して上のエラーは無くなりました。
|
317
|
+
次はNo method errorで止まってしましました。
|
318
|
+
|
319
|
+

|
320
|
+
|
321
|
+
model family.rb
|
322
|
+
```
|
323
|
+
class Family < ApplicationRecord
|
324
|
+
belongs_to :user
|
325
|
+
attachment :image
|
326
|
+
|
327
|
+
with_options presence: true do
|
328
|
+
validates :category
|
329
|
+
validates :molph
|
330
|
+
validates :image
|
331
|
+
validates :fathermolph
|
332
|
+
validates :mothermolph
|
333
|
+
validates :hatchdate
|
334
|
+
validates :sex
|
335
|
+
validates :weight
|
336
|
+
validates :feature
|
337
|
+
end
|
338
|
+
|
339
|
+
def get_serial
|
340
|
+
month = Date.parse(individualnumber+"/1").strftime("%y年%m月-")
|
341
|
+
number = Family.where("individualnumber like ?","#{month}%").
|
342
|
+
latest = where("individualnumber like ?","#{month}%").
|
343
|
+
order(individualnumber: :desc).first
|
344
|
+
number = latest ? latest.individualnumber[/月-(\d+)/,1].succ : 1
|
345
|
+
self.individualnumber = month + number
|
346
|
+
end
|
347
|
+
end
|
348
|
+
```
|
349
|
+
|
350
|
+
families.controller
|
351
|
+
```
|
352
|
+
class FamiliesController < ApplicationController
|
353
|
+
|
354
|
+
省略
|
355
|
+
def create
|
356
|
+
@family = Family.new(family_params)
|
357
|
+
@family.get_serial
|
358
|
+
@family.user_id = current_user.id
|
359
|
+
if @family.save
|
360
|
+
redirect_to family_path(@family), notice: "登録完了しました。"
|
361
|
+
else
|
362
|
+
render :new
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
def edit
|
367
|
+
@family = Family.find(params[:id])
|
368
|
+
if @family.user != current_user
|
369
|
+
redirect_to families_path, alert: "不正なアクセスです。"
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
def update
|
374
|
+
@family = Family.find(params[:id])
|
375
|
+
if @family.update(family_params)
|
376
|
+
redirect_to family_path(@family), notice: "更新に成功しました。"
|
377
|
+
else
|
378
|
+
render :edit
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
```
|
383
|
+
|
384
|
+
質問ばっかりすいません。
|
385
|
+
|
386
|
+
よろしくお願いします。
|
7
コメントを入力
title
CHANGED
File without changes
|
body
CHANGED
@@ -290,4 +290,22 @@
|
|
290
290
|
self.individualnumber = month + number
|
291
291
|
end
|
292
292
|
end
|
293
|
-
```
|
293
|
+
```
|
294
|
+
|
295
|
+
|
296
|
+
追記④
|
297
|
+
|
298
|
+
```modelfamily
|
299
|
+
def get_serial
|
300
|
+
month = Date.parse(individualnumber+"/1").strftime("%y年%m月-")
|
301
|
+
number = Family.where("individualnumber like ?","#{month}%").
|
302
|
+
latest = where("individualnumber like ?"."#{month}%").
|
303
|
+
order(individualnumber: :desc).first
|
304
|
+
number = latest ? latest.individualnumber[/月-(\d+)/,1].succ : 1
|
305
|
+
self.individualnumber = month + number
|
306
|
+
end
|
307
|
+
```
|
308
|
+
これでいいのですか?
|
309
|
+
|
310
|
+
以下のエラーになりました。
|
311
|
+

|
6
familyrbの変更を追記します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -266,14 +266,28 @@
|
|
266
266
|
何が違ってますでしょうか。
|
267
267
|
|
268
268
|
```familyrb
|
269
|
-
def create
|
270
|
-
|
269
|
+
class Family < ApplicationRecord
|
270
|
+
belongs_to :user
|
271
|
+
attachment :image
|
272
|
+
|
273
|
+
with_options presence: true do
|
274
|
+
validates :category
|
275
|
+
validates :molph
|
271
|
-
|
276
|
+
validates :image
|
272
|
-
|
277
|
+
validates :fathermolph
|
278
|
+
validates :mothermolph
|
273
|
-
|
279
|
+
validates :hatchdate
|
274
|
-
redirect_to family_path(@family), notice: "登録完了しました。"
|
275
|
-
else
|
276
|
-
|
280
|
+
validates :sex
|
277
|
-
|
281
|
+
validates :weight
|
282
|
+
validates :feature
|
278
283
|
end
|
284
|
+
|
285
|
+
def get_serial
|
286
|
+
month = Date.parse(individualnumber+"/1").strftime("%y年%m月-")
|
287
|
+
number = Family.where("individualnumber like ?","#{month}%").
|
288
|
+
order(individualnumber: :desc).
|
289
|
+
first.individualnumber[/月-(\d+)/,1].succ
|
290
|
+
self.individualnumber = month + number
|
291
|
+
end
|
292
|
+
end
|
279
293
|
```
|
5
最後のmodelのfamilyrbを変更しています。
title
CHANGED
File without changes
|
body
CHANGED
@@ -265,7 +265,7 @@
|
|
265
265
|
何を変更していいのやら全くわからないです。
|
266
266
|
何が違ってますでしょうか。
|
267
267
|
|
268
|
-
```
|
268
|
+
```familyrb
|
269
269
|
def create
|
270
270
|
@family = Family.new(family_params)
|
271
271
|
@family.get_serial
|
4
familycontrollerの中身を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -263,4 +263,17 @@
|
|
263
263
|
追記③
|
264
264
|

|
265
265
|
何を変更していいのやら全くわからないです。
|
266
|
-
何が違ってますでしょうか。
|
266
|
+
何が違ってますでしょうか。
|
267
|
+
|
268
|
+
```familycontroller
|
269
|
+
def create
|
270
|
+
@family = Family.new(family_params)
|
271
|
+
@family.get_serial
|
272
|
+
@family.user_id = current_user.id
|
273
|
+
if @family.save
|
274
|
+
redirect_to family_path(@family), notice: "登録完了しました。"
|
275
|
+
else
|
276
|
+
render :new
|
277
|
+
end
|
278
|
+
end
|
279
|
+
```
|
3
エラーに次ぐエラーで申し訳ありません。
title
CHANGED
File without changes
|
body
CHANGED
@@ -258,4 +258,9 @@
|
|
258
258
|

|
259
259
|
|
260
260
|
となります。
|
261
|
-
methodが定義されていないのでしょうか。。。
|
261
|
+
methodが定義されていないのでしょうか。。。
|
262
|
+
|
263
|
+
追記③
|
264
|
+

|
265
|
+
何を変更していいのやら全くわからないです。
|
266
|
+
何が違ってますでしょうか。
|
2
新しいエラーのため追記します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -208,4 +208,54 @@
|
|
208
208
|
```28
|
209
209
|
number = where("individualnumber like ?"."#{month}%").
|
210
210
|
```
|
211
|
-
です。
|
211
|
+
です。
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
追記2
|
217
|
+
```familymodel
|
218
|
+
class Family < ApplicationRecord
|
219
|
+
belongs_to :user
|
220
|
+
attachment :image
|
221
|
+
|
222
|
+
with_options presence: true do
|
223
|
+
validates :category
|
224
|
+
validates :molph
|
225
|
+
validates :image
|
226
|
+
validates :fathermolph
|
227
|
+
validates :mothermolph
|
228
|
+
validates :hatchdate
|
229
|
+
validates :sex
|
230
|
+
validates :weight
|
231
|
+
validates :feature
|
232
|
+
end
|
233
|
+
|
234
|
+
def get_serial
|
235
|
+
month = Date.parse(individualnumber+"/1").strftime("%y年%m月-")
|
236
|
+
number = Family.where("individualnumber like ?","#{month}%").
|
237
|
+
order(individualnumber: :desc).
|
238
|
+
first.individualnumber[/月-(\d+)/,1].succ
|
239
|
+
self.individualnumber = month + number
|
240
|
+
end
|
241
|
+
end
|
242
|
+
```
|
243
|
+
|
244
|
+
```familycontroller
|
245
|
+
def create
|
246
|
+
@family = Family.new(family_params)
|
247
|
+
@family = get_serial
|
248
|
+
@family.user_id = current_user.id
|
249
|
+
if @family.save
|
250
|
+
redirect_to family_path(@family), notice: "登録完了しました。"
|
251
|
+
else
|
252
|
+
render :new
|
253
|
+
end
|
254
|
+
end
|
255
|
+
```
|
256
|
+
|
257
|
+
上記ように変更しました。
|
258
|
+

|
259
|
+
|
260
|
+
となります。
|
261
|
+
methodが定義されていないのでしょうか。。。
|
1
回答いただいた内容で更新するとエラーが発生しましたので追記します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -175,4 +175,37 @@
|
|
175
175
|
```
|
176
176
|
|
177
177
|
|
178
|
-
よろしくお願いします。
|
178
|
+
よろしくお願いします。
|
179
|
+
|
180
|
+
|
181
|
+
追記
|
182
|
+
|
183
|
+
```familiescontroller
|
184
|
+
def create
|
185
|
+
@family = Family.new(family_params)
|
186
|
+
@family.get_serial
|
187
|
+
@family.user_id = current_user.id
|
188
|
+
if @family.save
|
189
|
+
redirect_to family_path(@family), notice: "登録完了しました。"
|
190
|
+
else
|
191
|
+
render :new
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def get_serial
|
196
|
+
month = Date.parse(individualnumber+"/1").strftime("%Y年%m月-")
|
197
|
+
number = where("individualnumber like ?"."#{month}%").
|
198
|
+
order(individualnumber: :desc).
|
199
|
+
first.individualnumber[/月-(\d+)/,1].succ
|
200
|
+
self.individualnumber = month + number
|
201
|
+
end
|
202
|
+
```
|
203
|
+
上記のように記載しました。
|
204
|
+
すると下記のエラーが出ています。
|
205
|
+
|
206
|
+
app/controllers/families_controller.rb:28: syntax error, unexpected tSTRING_BEG
|
207
|
+
app/controllers/families_controller.rb:28: syntax error, unexpected ')', expecting end
|
208
|
+
```28
|
209
|
+
number = where("individualnumber like ?"."#{month}%").
|
210
|
+
```
|
211
|
+
です。
|