質問編集履歴
3
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,346 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
+
|
38
|
+
|
39
|
+
### 該当のソースコード
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```Ruby
|
44
|
+
|
45
|
+
# model/dish.rb
|
46
|
+
|
47
|
+
class Dish < ApplicationRecord
|
48
|
+
|
49
|
+
validates :title, presence: true, uniqueness: true
|
50
|
+
|
51
|
+
has_many :ingredients, through: :ingredients_in_dishes
|
52
|
+
|
53
|
+
has_many :ingredients_in_dishes #dependent: :destroy
|
54
|
+
|
55
|
+
has_many :procedures, dependent: :destroy
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
```Ruby
|
64
|
+
|
65
|
+
# model/procedure.rb
|
66
|
+
|
67
|
+
class Procedure < ApplicationRecord
|
68
|
+
|
69
|
+
belongs_to :dish
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
mount_uploader :image, ImageUploader
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
```Ruby
|
80
|
+
|
81
|
+
# app/uploaders/image_uploader.rb
|
82
|
+
|
83
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
84
|
+
|
85
|
+
# Include RMagick or MiniMagick support:
|
86
|
+
|
87
|
+
# include CarrierWave::RMagick
|
88
|
+
|
89
|
+
# include CarrierWave::MiniMagick
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
# Choose what kind of storage to use for this uploader:
|
94
|
+
|
95
|
+
storage :file
|
96
|
+
|
97
|
+
# storage :fog
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# Override the directory where uploaded files will be stored.
|
102
|
+
|
103
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
104
|
+
|
105
|
+
def store_dir
|
106
|
+
|
107
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
114
|
+
|
115
|
+
# def default_url(*args)
|
116
|
+
|
117
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
118
|
+
|
119
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
120
|
+
|
121
|
+
#
|
122
|
+
|
123
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
124
|
+
|
125
|
+
# end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
# Process files as they are uploaded:
|
130
|
+
|
131
|
+
# process scale: [200, 300]
|
132
|
+
|
133
|
+
#
|
134
|
+
|
135
|
+
# def scale(width, height)
|
136
|
+
|
137
|
+
# # do something
|
138
|
+
|
139
|
+
# end
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
# Create different versions of your uploaded files:
|
144
|
+
|
145
|
+
# version :thumb do
|
146
|
+
|
147
|
+
# process resize_to_fit: [50, 50]
|
148
|
+
|
149
|
+
# end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
version :medium do
|
154
|
+
|
155
|
+
process resize_to_fill: [1080, 1080]
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
# Add an allowlist of extensions which are allowed to be uploaded.
|
162
|
+
|
163
|
+
# For images you might use something like this:
|
164
|
+
|
165
|
+
def extension_allowlist
|
166
|
+
|
167
|
+
%w(jpg jpeg gif png)
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
# Override the filename of the uploaded files:
|
174
|
+
|
175
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
176
|
+
|
177
|
+
# def filename
|
178
|
+
|
179
|
+
# "something.jpg" if original_filename
|
180
|
+
|
181
|
+
# end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
```Ruby
|
190
|
+
|
191
|
+
# controllers/procedures_controller.rb
|
192
|
+
|
193
|
+
class ProceduresController < ApplicationController
|
194
|
+
|
195
|
+
require 'byebug'
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
def create
|
200
|
+
|
201
|
+
dish = Dish.find_by(id: params[:dish_id])
|
202
|
+
|
203
|
+
@procedure = dish.procedures.build(procedure_params)
|
204
|
+
|
205
|
+
byebug
|
206
|
+
|
207
|
+
if @procedure.present?
|
208
|
+
|
209
|
+
@procedure.save
|
210
|
+
|
211
|
+
redirect_to dishes_path
|
212
|
+
|
213
|
+
flash[:notice] = "#{dish.title}に手順#{@procedure.order}を登録しました"
|
214
|
+
|
215
|
+
else
|
216
|
+
|
217
|
+
redirect_to new_dish_procedure_path
|
218
|
+
|
219
|
+
flash[:alert] = "登録に失敗しました"
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
private
|
228
|
+
|
229
|
+
def procedure_params
|
230
|
+
|
231
|
+
params.permit(
|
232
|
+
|
233
|
+
:dish_id, :introduction, :order, :image
|
234
|
+
|
235
|
+
)
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
def set_procedure
|
242
|
+
|
243
|
+
@procedure = Procedure.find_by(id: params[:id])
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
|
259
|
+
# views/procedures/new.html.erb
|
260
|
+
|
261
|
+
<div class="main">
|
262
|
+
|
263
|
+
<div class="card mt-2 w-75 mx-auto">
|
264
|
+
|
265
|
+
<div class="form-group text-center mt-4">
|
266
|
+
|
267
|
+
<h2 class="text-secondary"></h2>
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
<div class="form-wrap m-2">
|
272
|
+
|
273
|
+
<%= form_with model: @procedure, url: dish_procedures_path, local: true do |f| %>
|
274
|
+
|
275
|
+
<div class="form-group text-center w-75 mx-auto mt-2">
|
276
|
+
|
277
|
+
<%= label_tag(:order, "STEP", class:"mr-2") %>
|
278
|
+
|
279
|
+
<%= f.number_field :order, step: "1", required: true %>
|
280
|
+
|
281
|
+
</div>
|
282
|
+
|
283
|
+
<div class="form-group text-center w-75 mx-auto mt-2">
|
284
|
+
|
285
|
+
<%= f.text_area :introduction, required: true, placeholder: "作業工程" %>
|
286
|
+
|
287
|
+
</div>
|
288
|
+
|
289
|
+
<div class="form-group text-center w-75 mx-auto mt-2">
|
290
|
+
|
291
|
+
<%= f.file_field :image %>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
<div class="actions mt-4">
|
296
|
+
|
297
|
+
<%= f.submit "登録", class: "btn btn-primary d-block ms-auto" %>
|
298
|
+
|
299
|
+
</div>
|
300
|
+
|
301
|
+
<% end %>
|
302
|
+
|
303
|
+
</div>
|
304
|
+
|
305
|
+
</div>
|
306
|
+
|
307
|
+
</div>
|
308
|
+
|
309
|
+
```
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
|
313
|
+
#schema.rb
|
314
|
+
|
315
|
+
create_table "procedures", force: :cascade do |t|
|
316
|
+
|
317
|
+
t.string "image"
|
318
|
+
|
319
|
+
t.integer "dish_id", null: false
|
320
|
+
|
321
|
+
t.integer "order", null: false
|
322
|
+
|
323
|
+
t.text "introduction", null: false
|
324
|
+
|
325
|
+
t.datetime "created_at", precision: 6, null: false
|
326
|
+
|
327
|
+
t.datetime "updated_at", precision: 6, null: false
|
328
|
+
|
329
|
+
t.index ["dish_id"], name: "index_procedures_on_dish_id"
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
```
|
334
|
+
|
335
|
+
### 試したこと
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
carrier waveのドキュメント参照
|
340
|
+
|
341
|
+
gemの入れ直し
|
342
|
+
|
343
|
+
file_fieldの書き直し
|
344
|
+
|
345
|
+
byebugでのデバッグ
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
### 補足情報(FW/ツールのバージョンなど)
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
gem list
|
354
|
+
|
355
|
+
*** LOCAL GEMS ***
|
356
|
+
|
357
|
+
~~~~~~~~~~~~~~~~~~~
|
358
|
+
|
359
|
+
carrierwave (2.2.2)
|
360
|
+
|
361
|
+
mini_magick (4.11.0)
|
362
|
+
|
363
|
+
```
|
364
|
+
|
365
|
+
Big Sur ver.11.4
|
366
|
+
|
367
|
+
Rails 6.1.3.2
|
368
|
+
|
369
|
+
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-darwin19]
|
370
|
+
|
371
|
+
Homebrew 3.1.12
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
37
377
|
ここからは検証していて個人的に気になった部分です。
|
38
378
|
|
39
379
|
- Createアクション内に`byebug`を仕込んでもそれが呼ばれる前にこの画面が出ているのでそもそも`create`アクションがよばれてない。
|
@@ -42,7 +382,7 @@
|
|
42
382
|
|
43
383
|
- file_fieldでimageを設定しないで`submit`を押すと`create`アクションがきちんとよばれimage以外のデータの保存は問題なくできますが、Params(下記)にimageのハッシュが存在していませんでした。
|
44
384
|
|
45
|
-
(別
|
385
|
+
(別モデルのCreateアクションの場合、`null`を許容してるカラムのフォームに値を入れないで送信した場合でも `”カラム名”=>nil`のハッシュはParamsに含まれていた。)
|
46
386
|
|
47
387
|
|
48
388
|
|
@@ -58,340 +398,8 @@
|
|
58
398
|
|
59
399
|
|
60
400
|
|
61
|
-
|
401
|
+
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
402
|
+
|
66
|
-
|
67
|
-
# model/dish.rb
|
68
|
-
|
69
|
-
class Dish < ApplicationRecord
|
70
|
-
|
71
|
-
validates :title, presence: true, uniqueness: true
|
72
|
-
|
73
|
-
has_many :ingredients, through: :ingredients_in_dishes
|
74
|
-
|
75
|
-
has_many :ingredients_in_dishes #dependent: :destroy
|
76
|
-
|
77
|
-
has_many :procedures, dependent: :destroy
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
```
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
```Ruby
|
86
|
-
|
87
|
-
# model/procedure.rb
|
88
|
-
|
89
|
-
class Procedure < ApplicationRecord
|
90
|
-
|
91
|
-
belongs_to :dish
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
mount_uploader :image, ImageUploader
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
```
|
100
|
-
|
101
|
-
```Ruby
|
102
|
-
|
103
|
-
# app/uploaders/image_uploader.rb
|
104
|
-
|
105
|
-
class ImageUploader < CarrierWave::Uploader::Base
|
106
|
-
|
107
|
-
# Include RMagick or MiniMagick support:
|
108
|
-
|
109
|
-
# include CarrierWave::RMagick
|
110
|
-
|
111
|
-
# include CarrierWave::MiniMagick
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
# Choose what kind of storage to use for this uploader:
|
116
|
-
|
117
|
-
storage :file
|
118
|
-
|
119
|
-
# storage :fog
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
# Override the directory where uploaded files will be stored.
|
124
|
-
|
125
|
-
# This is a sensible default for uploaders that are meant to be mounted:
|
126
|
-
|
127
|
-
def store_dir
|
128
|
-
|
129
|
-
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
# Provide a default URL as a default if there hasn't been a file uploaded:
|
136
|
-
|
137
|
-
# def default_url(*args)
|
138
|
-
|
139
|
-
# # For Rails 3.1+ asset pipeline compatibility:
|
140
|
-
|
141
|
-
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
142
|
-
|
143
|
-
#
|
144
|
-
|
145
|
-
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
146
|
-
|
147
|
-
# end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
# Process files as they are uploaded:
|
152
|
-
|
153
|
-
# process scale: [200, 300]
|
154
|
-
|
155
|
-
#
|
156
|
-
|
157
|
-
# def scale(width, height)
|
158
|
-
|
159
|
-
# # do something
|
160
|
-
|
161
|
-
# end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
# Create different versions of your uploaded files:
|
166
|
-
|
167
|
-
# version :thumb do
|
168
|
-
|
169
|
-
# process resize_to_fit: [50, 50]
|
170
|
-
|
171
|
-
# end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
version :medium do
|
176
|
-
|
177
|
-
process resize_to_fill: [1080, 1080]
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
# Add an allowlist of extensions which are allowed to be uploaded.
|
184
|
-
|
185
|
-
# For images you might use something like this:
|
186
|
-
|
187
|
-
def extension_allowlist
|
188
|
-
|
189
|
-
%w(jpg jpeg gif png)
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
# Override the filename of the uploaded files:
|
196
|
-
|
197
|
-
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
198
|
-
|
199
|
-
# def filename
|
200
|
-
|
201
|
-
# "something.jpg" if original_filename
|
202
|
-
|
203
|
-
# end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
```
|
210
|
-
|
211
|
-
```Ruby
|
212
|
-
|
213
|
-
# controllers/procedures_controller.rb
|
214
|
-
|
215
|
-
class ProceduresController < ApplicationController
|
216
|
-
|
217
|
-
require 'byebug'
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
def create
|
222
|
-
|
223
|
-
dish = Dish.find_by(id: params[:dish_id])
|
224
|
-
|
225
|
-
@procedure = dish.procedures.build(procedure_params)
|
226
|
-
|
227
|
-
byebug
|
228
|
-
|
229
|
-
if @procedure.present?
|
230
|
-
|
231
|
-
@procedure.save
|
232
|
-
|
233
|
-
redirect_to dishes_path
|
234
|
-
|
235
|
-
flash[:notice] = "#{dish.title}に手順#{@procedure.order}を登録しました"
|
236
|
-
|
237
|
-
else
|
238
|
-
|
239
|
-
redirect_to new_dish_procedure_path
|
240
|
-
|
241
|
-
flash[:alert] = "登録に失敗しました"
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
private
|
250
|
-
|
251
|
-
def procedure_params
|
252
|
-
|
253
|
-
params.permit(
|
254
|
-
|
255
|
-
:dish_id, :introduction, :order, :image
|
256
|
-
|
257
|
-
)
|
258
|
-
|
259
|
-
end
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
def set_procedure
|
264
|
-
|
265
|
-
@procedure = Procedure.find_by(id: params[:id])
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
```
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
```ruby
|
280
|
-
|
281
|
-
# views/procedures/new.html.erb
|
282
|
-
|
283
|
-
<div class="main">
|
284
|
-
|
285
|
-
<div class="card mt-2 w-75 mx-auto">
|
286
|
-
|
287
|
-
<div class="form-group text-center mt-4">
|
288
|
-
|
289
|
-
<h2 class="text-secondary"></h2>
|
290
|
-
|
291
|
-
</div>
|
292
|
-
|
293
|
-
<div class="form-wrap m-2">
|
294
|
-
|
295
|
-
<%= form_with model: @procedure, url: dish_procedures_path, local: true do |f| %>
|
296
|
-
|
297
|
-
<div class="form-group text-center w-75 mx-auto mt-2">
|
298
|
-
|
299
|
-
<%= label_tag(:order, "STEP", class:"mr-2") %>
|
300
|
-
|
301
|
-
<%= f.number_field :order, step: "1", required: true %>
|
302
|
-
|
303
|
-
</div>
|
304
|
-
|
305
|
-
<div class="form-group text-center w-75 mx-auto mt-2">
|
306
|
-
|
307
|
-
<%= f.text_area :introduction, required: true, placeholder: "作業工程" %>
|
308
|
-
|
309
|
-
</div>
|
310
|
-
|
311
|
-
<div class="form-group text-center w-75 mx-auto mt-2">
|
312
|
-
|
313
|
-
<%= f.file_field :image %>
|
314
|
-
|
315
|
-
</div>
|
316
|
-
|
317
|
-
<div class="actions mt-4">
|
318
|
-
|
319
|
-
<%= f.submit "登録", class: "btn btn-primary d-block ms-auto" %>
|
320
|
-
|
321
|
-
</div>
|
322
|
-
|
323
|
-
<% end %>
|
324
|
-
|
325
|
-
</div>
|
326
|
-
|
327
|
-
</div>
|
328
|
-
|
329
|
-
</div>
|
330
|
-
|
331
|
-
```
|
332
|
-
|
333
|
-
```ruby
|
334
|
-
|
335
|
-
#schema.rb
|
336
|
-
|
337
|
-
create_table "procedures", force: :cascade do |t|
|
338
|
-
|
339
|
-
t.string "image"
|
340
|
-
|
341
|
-
t.integer "dish_id", null: false
|
342
|
-
|
343
|
-
t.integer "order", null: false
|
344
|
-
|
345
|
-
t.text "introduction", null: false
|
346
|
-
|
347
|
-
t.datetime "created_at", precision: 6, null: false
|
348
|
-
|
349
|
-
t.datetime "updated_at", precision: 6, null: false
|
350
|
-
|
351
|
-
t.index ["dish_id"], name: "index_procedures_on_dish_id"
|
352
|
-
|
353
|
-
end
|
354
|
-
|
355
|
-
```
|
356
|
-
|
357
|
-
### 試したこと
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
carrier waveのドキュメント参照
|
362
|
-
|
363
|
-
gemの入れ直し
|
364
|
-
|
365
|
-
|
403
|
+
上記の部分からView上での書き方の問題でしょうか。
|
366
|
-
|
367
|
-
byebugでのデバッグ
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
### 補足情報(FW/ツールのバージョンなど)
|
372
|
-
|
373
|
-
```
|
374
|
-
|
375
|
-
gem list
|
376
|
-
|
377
|
-
*** LOCAL GEMS ***
|
378
|
-
|
379
|
-
~~~~~~~~~~~~~~~~~~~
|
380
|
-
|
381
|
-
carrierwave (2.2.2)
|
382
|
-
|
383
|
-
mini_magick (4.11.0)
|
384
|
-
|
385
|
-
```
|
386
|
-
|
387
|
-
Big Sur ver.11.4
|
388
|
-
|
389
|
-
Rails 6.1.3.2
|
390
|
-
|
391
|
-
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-darwin19]
|
392
|
-
|
393
|
-
Homebrew 3.1.12
|
394
|
-
|
395
|
-
|
396
404
|
|
397
405
|
特に具体的なエラーも吐かず、調べても同様の記事が見つからなかったので正直手詰まりな状態です。どのような助けでも泣いて喜びます。何か必要な情報に不足があればお申し付けください。
|
2
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,11 +8,23 @@
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
11
|
-
`Dish`(料理)は親モデルのあたり、子モデル`Procedure`(作業手順)を`has_many`の関係性となります。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
`Dish`(料理)は親モデルのあたり、子モデル`Procedure`(作業手順)を`has_many`の関係性となります。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
`dish_id`を元にした`Procedure`のnew画面のフォームにてorder(作業順序),introduction(作業の具体的な工程),image(作業の画像)をparamsで送り`create`で保存したいです。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
![イメージ説明](037dd0d41322ed840e36235e53fb0473.png)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
その際に`f.file_field`に画像(`image`)を指定してSubmitを行うと
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
![イメージ説明](317390e392e98d640041b799de022685.png)
|
16
28
|
|
17
29
|
|
18
30
|
|
@@ -38,7 +50,7 @@
|
|
38
50
|
|
39
51
|
(byebug) params
|
40
52
|
|
41
|
-
#<ActionController::Parameters {"authenticity_token"=>"-IJxFpJVZRu6DjuELL3tKHQJmfgnK7zRcSya1iszS3LcL2_JP7X4WIM8FLlXuner1gZnSZRtnLcEZScLFf7cYw", "order"=>"
|
53
|
+
#<ActionController::Parameters {"authenticity_token"=>"-IJxFpJVZRu6DjuELL3tKHQJmfgnK7zRcSya1iszS3LcL2_JP7X4WIM8FLlXuner1gZnSZRtnLcEZScLFf7cYw", "order"=>"1", "introduction"=>"野菜の皮を剥く。", "commit"=>"登録", "controller"=>"procedures", "action"=>"create", "dish_id"=>"3"} permitted: false>
|
42
54
|
|
43
55
|
(byebug) continue
|
44
56
|
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,39 +8,29 @@
|
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
11
|
-
`Dish`(料理)は親モデルのあたり、子モデル`Procedure`(作業手順)を`has_many`の関係性となります。`dish_id`を元に`Procedure`を`create`で保存す
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
```
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
C
|
34
|
-
|
35
|
-
```
|
36
|
-
|
37
|
-
から動いていない。
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
ちなみにimageを設定しないで`submit`を押すと`create`がよばれimage以外のデータの保存は問題なくできますが、Params(下記)にimageのハッシュが存在していないのも気になるなと個人的に思っています。(別のモデルのフォームでは`null`を許容してるカラムのフォームに値を入れなくても `”カラム名”=>nil`のハッシュはParamsに含まれていた。)
|
42
|
-
|
43
|
-
|
11
|
+
`Dish`(料理)は親モデルのあたり、子モデル`Procedure`(作業手順)を`has_many`の関係性となります。`dish_id`を元にした`Procedure`のnew画面のフォームにてorder(作業順序 :int),introduction(作業の具体的な工程 :text),image(作業の画像 :text)をparamsとして`create`で保存したいです。その際に`f.file_field`に画像(`image`)を指定してSubmitを行うと
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
![![イメージ説明](fec2b34bca2c2498d6d648eb7c708cb9.png)]
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
との画面になります。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
ここからは検証していて個人的に気になった部分です。
|
26
|
+
|
27
|
+
- Createアクション内に`byebug`を仕込んでもそれが呼ばれる前にこの画面が出ているのでそもそも`create`アクションがよばれてない。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
- file_fieldでimageを設定しないで`submit`を押すと`create`アクションがきちんとよばれimage以外のデータの保存は問題なくできますが、Params(下記)にimageのハッシュが存在していませんでした。
|
32
|
+
|
33
|
+
(別のモデルのCreateアクションの場合、`null`を許容してるカラムのフォームに値を入れないで送信した場合でも `”カラム名”=>nil`のハッシュはParamsに含まれていた。)
|
44
34
|
|
45
35
|
|
46
36
|
|