質問編集履歴

1

choose,choiceモデル追加

2021/02/08 13:24

投稿

0W5E8fPq1EOm4yE
0W5E8fPq1EOm4yE

スコア13

test CHANGED
File without changes
test CHANGED
@@ -306,6 +306,62 @@
306
306
 
307
307
 
308
308
 
309
+ ```ここに言語名を入力
310
+
311
+ class Choose < ActiveHash::Base
312
+
313
+ self.data = [
314
+
315
+ { id: 1, name: '選んでください。' },
316
+
317
+ { id: 2, name: '○' },
318
+
319
+ { id: 3, name: '×' },
320
+
321
+ ]
322
+
323
+
324
+
325
+ include ActiveHash::Associations
326
+
327
+ has_many :questions
328
+
329
+
330
+
331
+ end
332
+
333
+ ```
334
+
335
+
336
+
337
+ ```ここに言語名を入力
338
+
339
+ class Choice < ApplicationRecord
340
+
341
+ extend ActiveHash::Associations::ActiveRecordExtensions
342
+
343
+ has_many :users
344
+
345
+ belongs_to :question
346
+
347
+ belongs_to :choose
348
+
349
+
350
+
351
+ with_options numericality: { other_than: 1, message: 'Select' }, presence: true do
352
+
353
+ validates :choose_id
354
+
355
+ end
356
+
357
+ end
358
+
359
+ ```
360
+
361
+
362
+
363
+
364
+
309
365
  ### 試したこと
310
366
 
311
367