質問するログイン新規登録

質問編集履歴

6

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

2021/08/11 03:45

投稿

kaoru-drosera
kaoru-drosera

スコア23

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

5

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

2021/08/11 03:44

投稿

kaoru-drosera
kaoru-drosera

スコア23

title CHANGED
File without changes
body CHANGED
@@ -7,9 +7,14 @@
7
7
 
8
8
  イメージとしては「効果音ラボ」の「効果音ポン出し」に保存機能がついたようなものです。もっと具体的に言うと「KLANG」に当たると思われます。
9
9
 
10
+ 効果音ラボ 効果音ポン出し
11
+ https://soundeffect-lab.info/pon/app.html
10
12
 
13
+ KLANG
14
+ http://m-tank.info/common/klang
11
15
 
12
16
 
17
+
13
18
  # 実現したいこと
14
19
 
15
20
  マウスクリック/キータッチで効果音を鳴らせるボタンが12あり、

4

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

2021/08/11 03:29

投稿

kaoru-drosera
kaoru-drosera

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- unknown attribute 'XXX' for XXX. で必要ないはずのカラムが要求される(更新: 210810)
1
+ unknown attribute 'XXX' for XXX. で必要ないはず/存在するはずのカラムが要求される(更新: 210810)
body CHANGED
@@ -44,6 +44,7 @@
44
44
  |:--|:--|:--|
45
45
  |id|id|-|
46
46
  |ユーザーid|user_id|bigint|
47
+ |ボタンごとの設定のid|seboard_id|bigint|
47
48
  |効果音(をDBに保存する際)の名前|sename|string|
48
49
  |効果音の音源データ|sedata|(binary)string|
49
50
 

3

回答者maisumakunの名前を追加。

2021/08/09 18:05

投稿

kaoru-drosera
kaoru-drosera

スコア23

title CHANGED
File without changes
body CHANGED
@@ -92,7 +92,8 @@
92
92
  ただ、外部キーなどリレーションに関わる問題であることには間違いないとは思います。
93
93
 
94
94
  #####(更新: 210810)
95
+
95
- ご回答ありがとうございます。
96
+ maisumakun様、ご回答ありがとうございます。
96
97
  sefileに、seboard_idを追加いたしました。
97
98
  しかしその結果、以下のようなエラーが出ています。
98
99
 
@@ -223,6 +224,7 @@
223
224
  ```
224
225
 
225
226
  ##### /db/schema.rb(更新:210810)
227
+ sefileに、カラム「**seboard_id**」を追加いたしました。
226
228
  ```ruby
227
229
  (略)
228
230
 

2

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

2021/08/09 17:50

投稿

kaoru-drosera
kaoru-drosera

スコア23

title CHANGED
@@ -1,1 +1,1 @@
1
- unknown attribute 'XXX' for XXX. で必要ないはずのカラムが要求される()
1
+ unknown attribute 'XXX' for XXX. で必要ないはずのカラムが要求される(更新: 210810)
body CHANGED
@@ -84,13 +84,24 @@
84
84
 
85
85
  が加わります。
86
86
 
87
- # 詰まっている箇所
87
+ # 詰まっている箇所(更新:210810)
88
88
 
89
89
  ![イメージ説明](1ac98607d7d260988d16a17adf04bdc2.png)
90
90
 
91
91
  **「unknown attribute 'XXX' for XXX.」**なのですが、存在しない、あるいは存在する必要がない要素を要求されている状態です。
92
92
  ただ、外部キーなどリレーションに関わる問題であることには間違いないとは思います。
93
93
 
94
+ #####(更新: 210810)
95
+ ご回答ありがとうございます。
96
+ sefileに、seboard_idを追加いたしました。
97
+ しかしその結果、以下のようなエラーが出ています。
98
+
99
+ ![イメージ説明](83a0e96166c65d4d5d22907775529bf6.png)
100
+
101
+ 「sefile_id」、要するにSefileクラスでは存在するはずのクラスがない、ということになると思われます。
102
+ Sefileもクラスである以上、idが存在しないとは考えにくいです。
103
+ 今の所、こればかりは不可解です。
104
+
94
105
  # 現在のコード
95
106
 
96
107
  ##### /app/models/sampler.rb
@@ -103,9 +114,6 @@
103
114
  has_many :seboards#, class_name: "Seboard", foreign_key: 'id'
104
115
  accepts_nested_attributes_for :seboards
105
116
 
106
- # has_many :sefiles
107
- # accepts_nested_attributes_for :sefiles
108
-
109
117
  has_one :sefile, :through => :seboards#, foreign_key: 'sefile_id'
110
118
  accepts_nested_attributes_for :sefile
111
119
 
@@ -182,35 +190,7 @@
182
190
 
183
191
  ##### /app/views/sampler/_save.html.erb
184
192
  ```html
185
- <%= form_with model: @sampler do |sp| %>
186
- <%= fields_for :seboards do |sb| %>
187
- <%= fields_for :sefile do |sf| %>
188
-
189
- <!-- 上段 -->
190
- <div id="bg-q" class="case-btn-q case-btn" onclick="play(soundQ, loopQ, loopValue_q); btnColorInit(btnColorQ, bg_Q)">
191
- <p>Q</p>
192
- <%= sb.hidden_field :position,:name=>"sampler[seboards_attributes][1][position]", :value => "1" %>
193
- <%= 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 %>
194
- <div class="radio-field_q">
195
- <%= sb.radio_button :btncoler, "1", :name=>"sampler[seboards_attributes][1][btncolor]", checked: true, :class=>"red" %>
196
- <%= sb.radio_button :btncoler, "2", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"blue" %>
197
- <%= sb.radio_button :btncoler, "3", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"white" %>
198
- </div><!-- .radio-field_q -->
199
- <%= 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 %>
200
- <%= sf.file_field :sedata, :name=>"sampler[seboards_attributes][1][sefile_attributes][sedata]", :id=>"selectFile_q", :onclick=>"readFile(soundQ, form_fileQ)" %>
201
- <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][1][sefile_attributes][sename]" %>
202
-
203
- </div><!-- .case-btn-d -->
204
- <div id="bg-w" class="case-btn-w case-btn" onclick="play(soundW, loopW, loopValue_w); btnColorInit(btnColorW, bg_W)">
205
- <p>W</p>
206
- (字数制限につき略)
207
- <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][2][sefile_attributes][sename]" %>
208
-
209
- </div><!-- .case-btn-d -->
210
-
211
- <%= sp.submit "保存する" %>
212
- <% end %>
213
-
193
+ # 字数制限につき一時的に削除 申し訳ありません
214
194
  ```
215
195
 
216
196
  ##### /app/models/seboard.rb
@@ -228,14 +208,12 @@
228
208
  end
229
209
  ```
230
210
 
231
- ##### /app/models/sefile.rb
211
+ ##### /app/models/sefile.rb(更新:210810)
232
212
  ```ruby
233
213
  class Sefile < ApplicationRecord
234
214
  belongs_to :user, class_name: "User", foreign_key: 'user_id'
235
- # belongs_to :samplers, through: :seboards
215
+ belongs_to :seboard, optional: true
236
- belongs_to :seboard#, class_name: "Seboard", foreign_key: 'seboard_id'
237
216
 
238
-
239
217
  mount_uploader :sedata, SeUploader
240
218
 
241
219
  # バリデーションはこれ以降に
@@ -244,21 +222,11 @@
244
222
 
245
223
  ```
246
224
 
247
- ##### /db/schema.rb
225
+ ##### /db/schema.rb(更新:210810)
248
226
  ```ruby
249
- # This file is auto-generated from the current state of the database. Instead
250
- # of editing this file, please use the migrations feature of Active Record to
251
- # incrementally modify your database, and then regenerate this schema definition.
252
- #
227
+ (略)
253
- # This file is the source Rails uses to define your schema when running `bin/rails
254
- # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
255
- # be faster and is potentially less error prone than running all of your
256
- # migrations from scratch. Old migrations may fail to apply correctly if those
257
- # migrations use external dependencies or application code.
258
- #
259
- # It's strongly recommended that you check this file into your version control system.
260
228
 
261
- ActiveRecord::Schema.define(version: 2021_08_08_075948) do
229
+ ActiveRecord::Schema.define(version: 2021_08_09_172009) do
262
230
 
263
231
  # These are extensions that must be enabled in order to support this database
264
232
  enable_extension "plpgsql"
@@ -273,7 +241,7 @@
273
241
 
274
242
  create_table "seboards", force: :cascade do |t|
275
243
  t.bigint "sampler_id", null: false
276
- t.bigint "sefile_id", null: false
244
+ t.bigint "sefile_id"
277
245
  t.integer "position"
278
246
  t.integer "btncolor"
279
247
  t.integer "volume"
@@ -287,9 +255,11 @@
287
255
  create_table "sefiles", force: :cascade do |t|
288
256
  t.bigint "user_id", null: false
289
257
  t.string "sename"
290
- t.binary "sedata"
258
+ t.string "sedata"
291
259
  t.datetime "created_at", precision: 6, null: false
292
260
  t.datetime "updated_at", precision: 6, null: false
261
+ t.bigint "seboard_id"
262
+ t.index ["seboard_id"], name: "index_sefiles_on_seboard_id"
293
263
  t.index ["user_id"], name: "index_sefiles_on_user_id"
294
264
  end
295
265
 
@@ -313,14 +283,12 @@
313
283
  add_foreign_key "sefiles", "users"
314
284
  end
315
285
 
286
+
316
287
  ```
317
288
 
318
289
 
319
290
 
320
- # 試したこと
321
291
 
322
-
323
-
324
292
  # 補足情報(FW/ツールのバージョンなど)
325
293
 
326
294
  ブラウザ:chrome(最新のバージョン)

1

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

2021/08/09 17:47

投稿

kaoru-drosera
kaoru-drosera

スコア23

title CHANGED
File without changes
body CHANGED
@@ -181,8 +181,36 @@
181
181
  ```
182
182
 
183
183
  ##### /app/views/sampler/_save.html.erb
184
- ```ruby
184
+ ```html
185
+ <%= form_with model: @sampler do |sp| %>
186
+ <%= fields_for :seboards do |sb| %>
187
+ <%= fields_for :sefile do |sf| %>
185
188
 
189
+ <!-- 上段 -->
190
+ <div id="bg-q" class="case-btn-q case-btn" onclick="play(soundQ, loopQ, loopValue_q); btnColorInit(btnColorQ, bg_Q)">
191
+ <p>Q</p>
192
+ <%= sb.hidden_field :position,:name=>"sampler[seboards_attributes][1][position]", :value => "1" %>
193
+ <%= 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 %>
194
+ <div class="radio-field_q">
195
+ <%= sb.radio_button :btncoler, "1", :name=>"sampler[seboards_attributes][1][btncolor]", checked: true, :class=>"red" %>
196
+ <%= sb.radio_button :btncoler, "2", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"blue" %>
197
+ <%= sb.radio_button :btncoler, "3", :name=>"sampler[seboards_attributes][1][btncolor]", :class=>"white" %>
198
+ </div><!-- .radio-field_q -->
199
+ <%= 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 %>
200
+ <%= sf.file_field :sedata, :name=>"sampler[seboards_attributes][1][sefile_attributes][sedata]", :id=>"selectFile_q", :onclick=>"readFile(soundQ, form_fileQ)" %>
201
+ <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][1][sefile_attributes][sename]" %>
202
+
203
+ </div><!-- .case-btn-d -->
204
+ <div id="bg-w" class="case-btn-w case-btn" onclick="play(soundW, loopW, loopValue_w); btnColorInit(btnColorW, bg_W)">
205
+ <p>W</p>
206
+ (字数制限につき略)
207
+ <%= sf.text_field :sename, :name=>"sampler[seboards_attributes][2][sefile_attributes][sename]" %>
208
+
209
+ </div><!-- .case-btn-d -->
210
+
211
+ <%= sp.submit "保存する" %>
212
+ <% end %>
213
+
186
214
  ```
187
215
 
188
216
  ##### /app/models/seboard.rb