質問編集履歴

6

本日210810を最終更新日とし、タイトルに反映。

2021/08/11 03:45

投稿

kaoru-drosera
kaoru-drosera

スコア23

test CHANGED
@@ -1 +1 @@
1
- unknown attribute 'XXX' for XXX. で必要ないはず/存在するはずのカラムが要求される(更新: 210810)
1
+ unknown attribute 'XXX' for XXX. で必要ないはず/存在するはずのカラムが要求される(最終更新: 210810)
test CHANGED
File without changes

5

冒頭に「効果音ラボ」と「KLANG」のリンクを追加。

2021/08/11 03:44

投稿

kaoru-drosera
kaoru-drosera

スコア23

test CHANGED
File without changes
test CHANGED
@@ -16,6 +16,16 @@
16
16
 
17
17
 
18
18
 
19
+ 効果音ラボ 効果音ポン出し
20
+
21
+ https://soundeffect-lab.info/pon/app.html
22
+
23
+
24
+
25
+ KLANG
26
+
27
+ http://m-tank.info/common/klang
28
+
19
29
 
20
30
 
21
31
 

4

テーブルの表にseboard_idを忘れていたので更新。

2021/08/11 03:29

投稿

kaoru-drosera
kaoru-drosera

スコア23

test CHANGED
@@ -1 +1 @@
1
- unknown attribute 'XXX' for XXX. で必要ないはずのカラムが要求される(更新: 210810)
1
+ unknown attribute 'XXX' for XXX. で必要ないはず/存在するはずのカラムが要求される(更新: 210810)
test CHANGED
@@ -90,6 +90,8 @@
90
90
 
91
91
  |ユーザーid|user_id|bigint|
92
92
 
93
+ |ボタンごとの設定のid|seboard_id|bigint|
94
+
93
95
  |効果音(をDBに保存する際)の名前|sename|string|
94
96
 
95
97
  |効果音の音源データ|sedata|(binary)string|

3

回答者maisumakunの名前を追加。

2021/08/09 18:05

投稿

kaoru-drosera
kaoru-drosera

スコア23

test CHANGED
File without changes
test CHANGED
@@ -186,7 +186,9 @@
186
186
 
187
187
  #####(更新: 210810)
188
188
 
189
+
190
+
189
- ご回答ありがとうございます。
191
+ maisumakun様、ご回答ありがとうございます。
190
192
 
191
193
  sefileに、seboard_idを追加いたしました。
192
194
 
@@ -448,6 +450,8 @@
448
450
 
449
451
  ##### /db/schema.rb(更新:210810)
450
452
 
453
+ sefileに、カラム「**seboard_id**」を追加いたしました。
454
+
451
455
  ```ruby
452
456
 
453
457
  (略)

2

回答があった通りに修正したところ新しい問題が発生。更新として追記した。

2021/08/09 17:50

投稿

kaoru-drosera
kaoru-drosera

スコア23

test CHANGED
@@ -1 +1 @@
1
- unknown attribute 'XXX' for XXX. で必要ないはずのカラムが要求される()
1
+ unknown attribute 'XXX' for XXX. で必要ないはずのカラムが要求される(更新: 210810)
test CHANGED
@@ -170,7 +170,7 @@
170
170
 
171
171
 
172
172
 
173
- # 詰まっている箇所
173
+ # 詰まっている箇所(更新:210810)
174
174
 
175
175
 
176
176
 
@@ -184,6 +184,28 @@
184
184
 
185
185
 
186
186
 
187
+ #####(更新: 210810)
188
+
189
+ ご回答ありがとうございます。
190
+
191
+ sefileに、seboard_idを追加いたしました。
192
+
193
+ しかしその結果、以下のようなエラーが出ています。
194
+
195
+
196
+
197
+ ![イメージ説明](83a0e96166c65d4d5d22907775529bf6.png)
198
+
199
+
200
+
201
+ 「sefile_id」、要するにSefileクラスでは存在するはずのクラスがない、ということになると思われます。
202
+
203
+ Sefileもクラスである以上、idが存在しないとは考えにくいです。
204
+
205
+ 今の所、こればかりは不可解です。
206
+
207
+
208
+
187
209
  # 現在のコード
188
210
 
189
211
 
@@ -208,435 +230,349 @@
208
230
 
209
231
 
210
232
 
233
+ has_one :sefile, :through => :seboards#, foreign_key: 'sefile_id'
234
+
235
+ accepts_nested_attributes_for :sefile
236
+
237
+
238
+
239
+ # バリデーション(予定)
240
+
241
+
242
+
243
+
244
+
245
+ end
246
+
247
+ ```
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+ ###### /app/controllers/sampler_controller.rb
256
+
257
+ ```ruby
258
+
259
+ class SamplerController < ApplicationController
260
+
261
+
262
+
263
+ before_action :authenticate_user!
264
+
265
+
266
+
267
+ # 投稿を一覧形式にする(予定)
268
+
269
+ def seindex
270
+
271
+ @samplers = Sampler.all
272
+
273
+ end
274
+
275
+
276
+
277
+ def save
278
+
279
+ @sampler = Sampler.find_or_initialize_by(sampler_name: params[:sampler_name])
280
+
281
+ end
282
+
283
+
284
+
285
+ def submit
286
+
287
+ @sampler = Sampler.find_or_initialize_by(sampler_name: params[:sampler_name])
288
+
289
+ # sampler_sefile = Sampler.seboard.sefile.find_or_initialize_by(sename: params[:sename], sedata: params[:sedata])
290
+
291
+ unless @sampler.persisted?
292
+
293
+ @sampler = Sampler.new(sampler_params)
294
+
295
+ @sampler.user_id = current_user.id
296
+
297
+
298
+
299
+ unless @sampler.save
300
+
301
+ flash[:danger] = "保存に失敗しました"
302
+
303
+ else
304
+
305
+ flash[:success] = "保存しました"
306
+
307
+ end
308
+
309
+
310
+
311
+ else
312
+
313
+ @sampler = Sampler.update_attrbutes!(update_sampler_params)
314
+
315
+ # @sampler.save
316
+
317
+
318
+
319
+ unless @sampler.save
320
+
321
+ flash[:danger] = "更新に失敗しました"
322
+
323
+ else
324
+
325
+ flash[:success] = "更新しました"
326
+
327
+ end
328
+
329
+
330
+
331
+ end
332
+
333
+
334
+
335
+ redirect_to root_path
336
+
337
+
338
+
339
+ end
340
+
341
+
342
+
343
+
344
+
345
+ def show
346
+
347
+ @sampler = Sampler.find(params[:id])
348
+
349
+ end
350
+
351
+
352
+
353
+ private
354
+
355
+
356
+
357
+ def sampler_params
358
+
359
+ params.require(:sampler).permit(:sampler_name, seboards_attributes: [:position, :btncolor, :volume, :loopable, sefile_attributes: [:sename, :sedata]])
360
+
361
+ end
362
+
363
+
364
+
365
+ def update_sampler_params
366
+
367
+ params.require(:sampler).permit(:sampler_name, seboards_attributes: [:position, :btncolor, :volume, :loopable, sefile_attributes: [:sename, :sedata, :id]])
368
+
369
+ end
370
+
371
+
372
+
373
+
374
+
375
+ end
376
+
377
+ ```
378
+
379
+
380
+
381
+ ##### /app/views/sampler/_save.html.erb
382
+
383
+ ```html
384
+
385
+ # 字数制限につき一時的に削除 申し訳ありません
386
+
387
+ ```
388
+
389
+
390
+
391
+ ##### /app/models/seboard.rb
392
+
393
+ ```ruby
394
+
395
+ class Seboard < ApplicationRecord
396
+
397
+ belongs_to :sampler
398
+
399
+
400
+
401
+ has_one :sefile#, class_name: "Sefile", foreign_key: 'id'
402
+
403
+ # ↑
404
+
211
- # has_many :sefiles
405
+ # has_many :sefiles にするとうまくいった。
406
+
407
+ # この調子だと下の式のものやviewとcontrollerに点在するsefileの設定も複数形にするといいのだろうが、こちらを単数形にしたい。
408
+
409
+ accepts_nested_attributes_for :sefile
212
410
 
213
411
  # accepts_nested_attributes_for :sefiles
214
412
 
215
413
 
216
414
 
217
- has_one :sefile, :through => :seboards#, foreign_key: 'sefile_id'
218
-
219
- accepts_nested_attributes_for :sefile
220
-
221
-
222
-
223
- # バリデーション(予定)
224
-
225
-
226
-
227
-
228
-
229
415
  end
230
416
 
231
417
  ```
232
418
 
233
419
 
234
420
 
235
-
236
-
237
-
238
-
239
- ###### /app/controllers/sampler_controller.rb
421
+ ##### /app/models/sefile.rb(更新:210810)
240
422
 
241
423
  ```ruby
242
424
 
243
- class SamplerController < ApplicationController
425
+ class Sefile < ApplicationRecord
426
+
244
-
427
+ belongs_to :user, class_name: "User", foreign_key: 'user_id'
245
-
246
-
428
+
247
- before_action :authenticate_user!
429
+ belongs_to :seboard, optional: true
248
-
249
-
250
-
251
- # 投稿を一覧形式にする(予定)
430
+
252
-
253
- def seindex
431
+
254
-
255
- @samplers = Sampler.all
432
+
256
-
257
- end
258
-
259
-
260
-
261
- def save
262
-
263
- @sampler = Sampler.find_or_initialize_by(sampler_name: params[:sampler_name])
264
-
265
- end
266
-
267
-
268
-
269
- def submit
270
-
271
- @sampler = Sampler.find_or_initialize_by(sampler_name: params[:sampler_name])
272
-
273
- # sampler_sefile = Sampler.seboard.sefile.find_or_initialize_by(sename: params[:sename], sedata: params[:sedata])
274
-
275
- unless @sampler.persisted?
276
-
277
- @sampler = Sampler.new(sampler_params)
433
+ mount_uploader :sedata, SeUploader
278
-
279
- @sampler.user_id = current_user.id
434
+
280
-
281
-
282
-
283
- unless @sampler.save
435
+
284
-
285
- flash[:danger] = "保存に失敗しました"
436
+
286
-
287
- else
288
-
289
- flash[:success] = "保存しました"
290
-
291
- end
292
-
293
-
294
-
295
- else
296
-
297
- @sampler = Sampler.update_attrbutes!(update_sampler_params)
298
-
299
- # @sampler.save
437
+ # バリデーションはこれ以降に
300
-
301
-
302
-
303
- unless @sampler.save
304
-
305
- flash[:danger] = "更新に失敗しました"
306
-
307
- else
308
-
309
- flash[:success] = "更新しました"
310
-
311
- end
312
-
313
-
314
-
315
- end
316
-
317
-
318
-
319
- redirect_to root_path
320
-
321
-
322
-
323
- end
324
-
325
-
326
-
327
-
328
-
329
- def show
330
-
331
- @sampler = Sampler.find(params[:id])
332
-
333
- end
334
-
335
-
336
-
337
- private
338
-
339
-
340
-
341
- def sampler_params
342
-
343
- params.require(:sampler).permit(:sampler_name, seboards_attributes: [:position, :btncolor, :volume, :loopable, sefile_attributes: [:sename, :sedata]])
344
-
345
- end
346
-
347
-
348
-
349
- def update_sampler_params
350
-
351
- params.require(:sampler).permit(:sampler_name, seboards_attributes: [:position, :btncolor, :volume, :loopable, sefile_attributes: [:sename, :sedata, :id]])
352
-
353
- end
354
-
355
-
356
438
 
357
439
 
358
440
 
359
441
  end
360
442
 
361
- ```
362
-
363
-
364
-
365
- ##### /app/views/sampler/_save.html.erb
366
-
367
- ```html
368
-
369
- <%= form_with model: @sampler do |sp| %>
370
-
371
- <%= fields_for :seboards do |sb| %>
372
-
373
- <%= fields_for :sefile do |sf| %>
374
-
375
-
376
-
377
- <!-- 上段 -->
378
-
379
- <div id="bg-q" class="case-btn-q case-btn" onclick="play(soundQ, loopQ, loopValue_q); btnColorInit(btnColorQ, bg_Q)">
380
-
381
- <p>Q</p>
382
-
383
- <%= sb.hidden_field :position,:name=>"sampler[seboards_attributes][1][position]", :value => "1" %>
384
-
385
- <%= sb.range_field :volume, :name=>"sampler[seboards_attributes][1][volume]", :onchange=>"volumeInit(soundQ, volumeQ, volumeValue_q)", :id=>"vol-q", :value=>50, :min=>1, :max=>99 %>
386
-
387
- <div class="radio-field_q">
388
-
389
- <%= sb.radio_button :btncoler, "1", :name=>"sampler[seboards_attributes][1][btncolor]", checked: true, :class=>"red" %>
390
-
391
- <%= sb.radio_button :btncoler, "2", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"blue" %>
392
-
393
- <%= sb.radio_button :btncoler, "3", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"white" %>
394
-
395
- </div><!-- .radio-field_q -->
396
-
397
- <%= sb.check_box "loopable", :name=>"sampler[seboards_attributes][1][loopable]", :onclick=>"loopInit(soundQ, loopQ, loopValue_q)", :id=>"loopable_q", :checked_value =>true, :unchecked_value=>false %>
398
-
399
- <%= sf.file_field :sedata, :name=>"sampler[seboards_attributes][1][sefile_attributes][sedata]", :id=>"selectFile_q", :onclick=>"readFile(soundQ, form_fileQ)" %>
400
-
401
- <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][1][sefile_attributes][sename]" %>
402
-
403
-
404
-
405
- </div><!-- .case-btn-d -->
406
-
407
- <div id="bg-w" class="case-btn-w case-btn" onclick="play(soundW, loopW, loopValue_w); btnColorInit(btnColorW, bg_W)">
408
-
409
- <p>W</p>
410
-
411
- (字数制限につき略)
412
-
413
- <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][2][sefile_attributes][sename]" %>
414
-
415
-
416
-
417
- </div><!-- .case-btn-d -->
418
-
419
-
420
-
421
- <%= sp.submit "保存する" %>
422
-
423
- <% end %>
424
-
425
-
426
-
427
- ```
428
-
429
-
430
-
431
- ##### /app/models/seboard.rb
443
+
444
+
445
+ ```
446
+
447
+
448
+
449
+ ##### /db/schema.rb(更新:210810)
432
450
 
433
451
  ```ruby
434
452
 
453
+ (略)
454
+
455
+
456
+
457
+ ActiveRecord::Schema.define(version: 2021_08_09_172009) do
458
+
459
+
460
+
461
+ # These are extensions that must be enabled in order to support this database
462
+
463
+ enable_extension "plpgsql"
464
+
465
+
466
+
467
+ create_table "samplers", force: :cascade do |t|
468
+
469
+ t.bigint "user_id", null: false
470
+
471
+ t.string "sampler_name"
472
+
473
+ t.datetime "created_at", precision: 6, null: false
474
+
475
+ t.datetime "updated_at", precision: 6, null: false
476
+
477
+ t.index ["user_id"], name: "index_samplers_on_user_id"
478
+
479
+ end
480
+
481
+
482
+
483
+ create_table "seboards", force: :cascade do |t|
484
+
485
+ t.bigint "sampler_id", null: false
486
+
487
+ t.bigint "sefile_id"
488
+
435
- class Seboard < ApplicationRecord
489
+ t.integer "position"
490
+
436
-
491
+ t.integer "btncolor"
492
+
493
+ t.integer "volume"
494
+
437
- belongs_to :sampler
495
+ t.boolean "loopable"
496
+
438
-
497
+ t.datetime "created_at", precision: 6, null: false
498
+
439
-
499
+ t.datetime "updated_at", precision: 6, null: false
500
+
440
-
501
+ t.index ["sampler_id"], name: "index_seboards_on_sampler_id"
502
+
503
+ t.index ["sefile_id"], name: "index_seboards_on_sefile_id"
504
+
505
+ end
506
+
507
+
508
+
441
- has_one :sefile#, class_name: "Sefile", foreign_key: 'id'
509
+ create_table "sefiles", force: :cascade do |t|
442
-
510
+
443
- #
511
+ t.bigint "user_id", null: false
444
-
512
+
445
- # has_many :sefiles にするとうまくいった。
513
+ t.string "sename"
514
+
446
-
515
+ t.string "sedata"
516
+
517
+ t.datetime "created_at", precision: 6, null: false
518
+
519
+ t.datetime "updated_at", precision: 6, null: false
520
+
521
+ t.bigint "seboard_id"
522
+
523
+ t.index ["seboard_id"], name: "index_sefiles_on_seboard_id"
524
+
447
- # この調子だと下の式のものやviewとcontrollerに点在するsefileの設定も複数形にするといいのだろうが、こちらを単数形にしたい。
525
+ t.index ["user_id"], name: "index_sefiles_on_user_id"
526
+
448
-
527
+ end
528
+
529
+
530
+
449
- accepts_nested_attributes_for :sefile
531
+ create_table "users", force: :cascade do |t|
532
+
450
-
533
+ t.string "user_name"
534
+
535
+ t.datetime "created_at", precision: 6, null: false
536
+
537
+ t.datetime "updated_at", precision: 6, null: false
538
+
539
+ t.string "password_digest"
540
+
541
+ t.string "email", default: "", null: false
542
+
543
+ t.string "encrypted_password", default: "", null: false
544
+
545
+ t.string "reset_password_token"
546
+
547
+ t.datetime "reset_password_sent_at"
548
+
549
+ t.datetime "remember_created_at"
550
+
551
+ t.index ["email"], name: "index_users_on_email", unique: true
552
+
553
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
554
+
555
+ end
556
+
557
+
558
+
559
+ add_foreign_key "samplers", "users"
560
+
561
+ add_foreign_key "seboards", "samplers"
562
+
451
- # accepts_nested_attributes_for :sefiles
563
+ add_foreign_key "seboards", "sefiles"
564
+
452
-
565
+ add_foreign_key "sefiles", "users"
453
-
454
566
 
455
567
  end
456
568
 
569
+
570
+
571
+
572
+
457
- ```
573
+ ```
458
-
459
-
460
-
461
- ##### /app/models/sefile.rb
574
+
462
-
463
- ```ruby
575
+
464
-
465
- class Sefile < ApplicationRecord
466
-
467
- belongs_to :user, class_name: "User", foreign_key: 'user_id'
468
-
469
- # belongs_to :samplers, through: :seboards
470
-
471
- belongs_to :seboard#, class_name: "Seboard", foreign_key: 'seboard_id'
472
-
473
-
474
-
475
-
476
-
477
- mount_uploader :sedata, SeUploader
478
-
479
-
480
-
481
- # バリデーションはこれ以降に
482
-
483
-
484
-
485
- end
486
-
487
-
488
-
489
- ```
490
-
491
-
492
-
493
- ##### /db/schema.rb
494
-
495
- ```ruby
496
-
497
- # This file is auto-generated from the current state of the database. Instead
498
-
499
- # of editing this file, please use the migrations feature of Active Record to
500
-
501
- # incrementally modify your database, and then regenerate this schema definition.
502
-
503
- #
504
-
505
- # This file is the source Rails uses to define your schema when running `bin/rails
506
-
507
- # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
508
-
509
- # be faster and is potentially less error prone than running all of your
510
-
511
- # migrations from scratch. Old migrations may fail to apply correctly if those
512
-
513
- # migrations use external dependencies or application code.
514
-
515
- #
516
-
517
- # It's strongly recommended that you check this file into your version control system.
518
-
519
-
520
-
521
- ActiveRecord::Schema.define(version: 2021_08_08_075948) do
522
-
523
-
524
-
525
- # These are extensions that must be enabled in order to support this database
526
-
527
- enable_extension "plpgsql"
528
-
529
-
530
-
531
- create_table "samplers", force: :cascade do |t|
532
-
533
- t.bigint "user_id", null: false
534
-
535
- t.string "sampler_name"
536
-
537
- t.datetime "created_at", precision: 6, null: false
538
-
539
- t.datetime "updated_at", precision: 6, null: false
540
-
541
- t.index ["user_id"], name: "index_samplers_on_user_id"
542
-
543
- end
544
-
545
-
546
-
547
- create_table "seboards", force: :cascade do |t|
548
-
549
- t.bigint "sampler_id", null: false
550
-
551
- t.bigint "sefile_id", null: false
552
-
553
- t.integer "position"
554
-
555
- t.integer "btncolor"
556
-
557
- t.integer "volume"
558
-
559
- t.boolean "loopable"
560
-
561
- t.datetime "created_at", precision: 6, null: false
562
-
563
- t.datetime "updated_at", precision: 6, null: false
564
-
565
- t.index ["sampler_id"], name: "index_seboards_on_sampler_id"
566
-
567
- t.index ["sefile_id"], name: "index_seboards_on_sefile_id"
568
-
569
- end
570
-
571
-
572
-
573
- create_table "sefiles", force: :cascade do |t|
574
-
575
- t.bigint "user_id", null: false
576
-
577
- t.string "sename"
578
-
579
- t.binary "sedata"
580
-
581
- t.datetime "created_at", precision: 6, null: false
582
-
583
- t.datetime "updated_at", precision: 6, null: false
584
-
585
- t.index ["user_id"], name: "index_sefiles_on_user_id"
586
-
587
- end
588
-
589
-
590
-
591
- create_table "users", force: :cascade do |t|
592
-
593
- t.string "user_name"
594
-
595
- t.datetime "created_at", precision: 6, null: false
596
-
597
- t.datetime "updated_at", precision: 6, null: false
598
-
599
- t.string "password_digest"
600
-
601
- t.string "email", default: "", null: false
602
-
603
- t.string "encrypted_password", default: "", null: false
604
-
605
- t.string "reset_password_token"
606
-
607
- t.datetime "reset_password_sent_at"
608
-
609
- t.datetime "remember_created_at"
610
-
611
- t.index ["email"], name: "index_users_on_email", unique: true
612
-
613
- t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
614
-
615
- end
616
-
617
-
618
-
619
- add_foreign_key "samplers", "users"
620
-
621
- add_foreign_key "seboards", "samplers"
622
-
623
- add_foreign_key "seboards", "sefiles"
624
-
625
- add_foreign_key "sefiles", "users"
626
-
627
- end
628
-
629
-
630
-
631
- ```
632
-
633
-
634
-
635
-
636
-
637
-
638
-
639
- # 試したこと
640
576
 
641
577
 
642
578
 

1

「/app/views/sampler/_save.html.erb」のコードがまるっと抜けていたので足しました。

2021/08/09 17:47

投稿

kaoru-drosera
kaoru-drosera

スコア23

test CHANGED
File without changes
test CHANGED
@@ -364,67 +364,265 @@
364
364
 
365
365
  ##### /app/views/sampler/_save.html.erb
366
366
 
367
+ ```html
368
+
369
+ <%= form_with model: @sampler do |sp| %>
370
+
371
+ <%= fields_for :seboards do |sb| %>
372
+
373
+ <%= fields_for :sefile do |sf| %>
374
+
375
+
376
+
377
+ <!-- 上段 -->
378
+
379
+ <div id="bg-q" class="case-btn-q case-btn" onclick="play(soundQ, loopQ, loopValue_q); btnColorInit(btnColorQ, bg_Q)">
380
+
381
+ <p>Q</p>
382
+
383
+ <%= sb.hidden_field :position,:name=>"sampler[seboards_attributes][1][position]", :value => "1" %>
384
+
385
+ <%= sb.range_field :volume, :name=>"sampler[seboards_attributes][1][volume]", :onchange=>"volumeInit(soundQ, volumeQ, volumeValue_q)", :id=>"vol-q", :value=>50, :min=>1, :max=>99 %>
386
+
387
+ <div class="radio-field_q">
388
+
389
+ <%= sb.radio_button :btncoler, "1", :name=>"sampler[seboards_attributes][1][btncolor]", checked: true, :class=>"red" %>
390
+
391
+ <%= sb.radio_button :btncoler, "2", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"blue" %>
392
+
393
+ <%= sb.radio_button :btncoler, "3", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"white" %>
394
+
395
+ </div><!-- .radio-field_q -->
396
+
397
+ <%= sb.check_box "loopable", :name=>"sampler[seboards_attributes][1][loopable]", :onclick=>"loopInit(soundQ, loopQ, loopValue_q)", :id=>"loopable_q", :checked_value =>true, :unchecked_value=>false %>
398
+
399
+ <%= sf.file_field :sedata, :name=>"sampler[seboards_attributes][1][sefile_attributes][sedata]", :id=>"selectFile_q", :onclick=>"readFile(soundQ, form_fileQ)" %>
400
+
401
+ <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][1][sefile_attributes][sename]" %>
402
+
403
+
404
+
405
+ </div><!-- .case-btn-d -->
406
+
407
+ <div id="bg-w" class="case-btn-w case-btn" onclick="play(soundW, loopW, loopValue_w); btnColorInit(btnColorW, bg_W)">
408
+
409
+ <p>W</p>
410
+
411
+ (字数制限につき略)
412
+
413
+ <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][2][sefile_attributes][sename]" %>
414
+
415
+
416
+
417
+ </div><!-- .case-btn-d -->
418
+
419
+
420
+
421
+ <%= sp.submit "保存する" %>
422
+
423
+ <% end %>
424
+
425
+
426
+
427
+ ```
428
+
429
+
430
+
431
+ ##### /app/models/seboard.rb
432
+
367
433
  ```ruby
368
434
 
369
-
435
+ class Seboard < ApplicationRecord
436
+
370
-
437
+ belongs_to :sampler
438
+
439
+
440
+
441
+ has_one :sefile#, class_name: "Sefile", foreign_key: 'id'
442
+
443
+ # ↑
444
+
445
+ # has_many :sefiles にするとうまくいった。
446
+
447
+ # この調子だと下の式のものやviewとcontrollerに点在するsefileの設定も複数形にするといいのだろうが、こちらを単数形にしたい。
448
+
449
+ accepts_nested_attributes_for :sefile
450
+
451
+ # accepts_nested_attributes_for :sefiles
452
+
453
+
454
+
455
+ end
456
+
371
- ```
457
+ ```
372
-
373
-
374
-
458
+
459
+
460
+
375
- ##### /app/models/seboard.rb
461
+ ##### /app/models/sefile.rb
376
462
 
377
463
  ```ruby
378
464
 
379
- class Seboard < ApplicationRecord
465
+ class Sefile < ApplicationRecord
380
-
381
- belongs_to :sampler
466
+
382
-
383
-
384
-
385
- has_one :sefile#, class_name: "Sefile", foreign_key: 'id'
467
+ belongs_to :user, class_name: "User", foreign_key: 'user_id'
386
-
387
- # ↑
468
+
388
-
389
- # has_many :sefiles にするとうまくいった。
390
-
391
- # この調子だと下の式のものやviewとcontrollerに点在するsefileの設定も複数形にするといいのだろうが、こちらを単数形にしたい。
392
-
393
- accepts_nested_attributes_for :sefile
394
-
395
- # accepts_nested_attributes_for :sefiles
469
+ # belongs_to :samplers, through: :seboards
470
+
471
+ belongs_to :seboard#, class_name: "Seboard", foreign_key: 'seboard_id'
472
+
473
+
474
+
475
+
476
+
477
+ mount_uploader :sedata, SeUploader
478
+
479
+
480
+
481
+ # バリデーションはこれ以降に
396
482
 
397
483
 
398
484
 
399
485
  end
400
486
 
487
+
488
+
401
- ```
489
+ ```
402
-
403
-
404
-
490
+
491
+
492
+
405
- ##### /app/models/sefile.rb
493
+ ##### /db/schema.rb
406
494
 
407
495
  ```ruby
408
496
 
497
+ # This file is auto-generated from the current state of the database. Instead
498
+
499
+ # of editing this file, please use the migrations feature of Active Record to
500
+
501
+ # incrementally modify your database, and then regenerate this schema definition.
502
+
503
+ #
504
+
505
+ # This file is the source Rails uses to define your schema when running `bin/rails
506
+
507
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
508
+
509
+ # be faster and is potentially less error prone than running all of your
510
+
511
+ # migrations from scratch. Old migrations may fail to apply correctly if those
512
+
513
+ # migrations use external dependencies or application code.
514
+
515
+ #
516
+
517
+ # It's strongly recommended that you check this file into your version control system.
518
+
519
+
520
+
521
+ ActiveRecord::Schema.define(version: 2021_08_08_075948) do
522
+
523
+
524
+
525
+ # These are extensions that must be enabled in order to support this database
526
+
527
+ enable_extension "plpgsql"
528
+
529
+
530
+
531
+ create_table "samplers", force: :cascade do |t|
532
+
533
+ t.bigint "user_id", null: false
534
+
409
- class Sefile < ApplicationRecord
535
+ t.string "sampler_name"
536
+
410
-
537
+ t.datetime "created_at", precision: 6, null: false
538
+
539
+ t.datetime "updated_at", precision: 6, null: false
540
+
411
- belongs_to :user, class_name: "User", foreign_key: 'user_id'
541
+ t.index ["user_id"], name: "index_samplers_on_user_id"
542
+
412
-
543
+ end
544
+
545
+
546
+
547
+ create_table "seboards", force: :cascade do |t|
548
+
413
- # belongs_to :samplers, through: :seboards
549
+ t.bigint "sampler_id", null: false
550
+
414
-
551
+ t.bigint "sefile_id", null: false
552
+
553
+ t.integer "position"
554
+
555
+ t.integer "btncolor"
556
+
557
+ t.integer "volume"
558
+
559
+ t.boolean "loopable"
560
+
561
+ t.datetime "created_at", precision: 6, null: false
562
+
563
+ t.datetime "updated_at", precision: 6, null: false
564
+
565
+ t.index ["sampler_id"], name: "index_seboards_on_sampler_id"
566
+
415
- belongs_to :seboard#, class_name: "Seboard", foreign_key: 'seboard_id'
567
+ t.index ["sefile_id"], name: "index_seboards_on_sefile_id"
568
+
416
-
569
+ end
570
+
571
+
572
+
417
-
573
+ create_table "sefiles", force: :cascade do |t|
418
-
419
-
420
-
574
+
421
- mount_uploader :sedata, SeUploader
575
+ t.bigint "user_id", null: false
422
-
423
-
424
-
576
+
425
- # バリデーションはこれ以降に
577
+ t.string "sename"
578
+
426
-
579
+ t.binary "sedata"
580
+
427
-
581
+ t.datetime "created_at", precision: 6, null: false
582
+
583
+ t.datetime "updated_at", precision: 6, null: false
584
+
585
+ t.index ["user_id"], name: "index_sefiles_on_user_id"
586
+
587
+ end
588
+
589
+
590
+
591
+ create_table "users", force: :cascade do |t|
592
+
593
+ t.string "user_name"
594
+
595
+ t.datetime "created_at", precision: 6, null: false
596
+
597
+ t.datetime "updated_at", precision: 6, null: false
598
+
599
+ t.string "password_digest"
600
+
601
+ t.string "email", default: "", null: false
602
+
603
+ t.string "encrypted_password", default: "", null: false
604
+
605
+ t.string "reset_password_token"
606
+
607
+ t.datetime "reset_password_sent_at"
608
+
609
+ t.datetime "remember_created_at"
610
+
611
+ t.index ["email"], name: "index_users_on_email", unique: true
612
+
613
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
614
+
615
+ end
616
+
617
+
618
+
619
+ add_foreign_key "samplers", "users"
620
+
621
+ add_foreign_key "seboards", "samplers"
622
+
623
+ add_foreign_key "seboards", "sefiles"
624
+
625
+ add_foreign_key "sefiles", "users"
428
626
 
429
627
  end
430
628
 
@@ -434,148 +632,6 @@
434
632
 
435
633
 
436
634
 
437
- ##### /db/schema.rb
438
-
439
- ```ruby
440
-
441
- # This file is auto-generated from the current state of the database. Instead
442
-
443
- # of editing this file, please use the migrations feature of Active Record to
444
-
445
- # incrementally modify your database, and then regenerate this schema definition.
446
-
447
- #
448
-
449
- # This file is the source Rails uses to define your schema when running `bin/rails
450
-
451
- # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
452
-
453
- # be faster and is potentially less error prone than running all of your
454
-
455
- # migrations from scratch. Old migrations may fail to apply correctly if those
456
-
457
- # migrations use external dependencies or application code.
458
-
459
- #
460
-
461
- # It's strongly recommended that you check this file into your version control system.
462
-
463
-
464
-
465
- ActiveRecord::Schema.define(version: 2021_08_08_075948) do
466
-
467
-
468
-
469
- # These are extensions that must be enabled in order to support this database
470
-
471
- enable_extension "plpgsql"
472
-
473
-
474
-
475
- create_table "samplers", force: :cascade do |t|
476
-
477
- t.bigint "user_id", null: false
478
-
479
- t.string "sampler_name"
480
-
481
- t.datetime "created_at", precision: 6, null: false
482
-
483
- t.datetime "updated_at", precision: 6, null: false
484
-
485
- t.index ["user_id"], name: "index_samplers_on_user_id"
486
-
487
- end
488
-
489
-
490
-
491
- create_table "seboards", force: :cascade do |t|
492
-
493
- t.bigint "sampler_id", null: false
494
-
495
- t.bigint "sefile_id", null: false
496
-
497
- t.integer "position"
498
-
499
- t.integer "btncolor"
500
-
501
- t.integer "volume"
502
-
503
- t.boolean "loopable"
504
-
505
- t.datetime "created_at", precision: 6, null: false
506
-
507
- t.datetime "updated_at", precision: 6, null: false
508
-
509
- t.index ["sampler_id"], name: "index_seboards_on_sampler_id"
510
-
511
- t.index ["sefile_id"], name: "index_seboards_on_sefile_id"
512
-
513
- end
514
-
515
-
516
-
517
- create_table "sefiles", force: :cascade do |t|
518
-
519
- t.bigint "user_id", null: false
520
-
521
- t.string "sename"
522
-
523
- t.binary "sedata"
524
-
525
- t.datetime "created_at", precision: 6, null: false
526
-
527
- t.datetime "updated_at", precision: 6, null: false
528
-
529
- t.index ["user_id"], name: "index_sefiles_on_user_id"
530
-
531
- end
532
-
533
-
534
-
535
- create_table "users", force: :cascade do |t|
536
-
537
- t.string "user_name"
538
-
539
- t.datetime "created_at", precision: 6, null: false
540
-
541
- t.datetime "updated_at", precision: 6, null: false
542
-
543
- t.string "password_digest"
544
-
545
- t.string "email", default: "", null: false
546
-
547
- t.string "encrypted_password", default: "", null: false
548
-
549
- t.string "reset_password_token"
550
-
551
- t.datetime "reset_password_sent_at"
552
-
553
- t.datetime "remember_created_at"
554
-
555
- t.index ["email"], name: "index_users_on_email", unique: true
556
-
557
- t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
558
-
559
- end
560
-
561
-
562
-
563
- add_foreign_key "samplers", "users"
564
-
565
- add_foreign_key "seboards", "samplers"
566
-
567
- add_foreign_key "seboards", "sefiles"
568
-
569
- add_foreign_key "sefiles", "users"
570
-
571
- end
572
-
573
-
574
-
575
- ```
576
-
577
-
578
-
579
635
 
580
636
 
581
637