質問編集履歴
1
モデルについて情報を追記いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -310,6 +310,92 @@
|
|
310
310
|
|
311
311
|
|
312
312
|
|
313
|
+
モデル
|
314
|
+
|
315
|
+
```bank
|
316
|
+
|
317
|
+
class Bank < ApplicationRecord
|
318
|
+
|
319
|
+
has_many :bank_categories
|
320
|
+
|
321
|
+
has_many :categories, through: :bank_categories
|
322
|
+
|
323
|
+
has_many :contents
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
validates :name, presence: true
|
328
|
+
|
329
|
+
validates :name, uniqueness: true
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
```
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
```category
|
338
|
+
|
339
|
+
class Category < ApplicationRecord
|
340
|
+
|
341
|
+
has_many :bank_categories
|
342
|
+
|
343
|
+
has_many :banks, through: :bank_categories
|
344
|
+
|
345
|
+
has_many :contents
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
validates :subject, uniqueness: true
|
350
|
+
|
351
|
+
validates :number, uniqueness: true
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
```
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
```bankcategory
|
360
|
+
|
361
|
+
class BankCategory < ApplicationRecord
|
362
|
+
|
363
|
+
belongs_to :bank
|
364
|
+
|
365
|
+
belongs_to :category
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
```
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
```content
|
374
|
+
|
375
|
+
class Content < ApplicationRecord
|
376
|
+
|
377
|
+
belongs_to :bank
|
378
|
+
|
379
|
+
belongs_to :category
|
380
|
+
|
381
|
+
belongs_to :user
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
validates :detail, presence: true
|
386
|
+
|
387
|
+
validates :bank_id, presence: true
|
388
|
+
|
389
|
+
validates :category_id, presence: true
|
390
|
+
|
391
|
+
validates :user_id, presence: true
|
392
|
+
|
393
|
+
end
|
394
|
+
|
395
|
+
```
|
396
|
+
|
397
|
+
|
398
|
+
|
313
399
|
※上記テーブルのように情報が登録できればベストだと考えています。
|
314
400
|
|
315
401
|
|