質問編集履歴
2
コントローラーのdef searchのpをqに、def search_stock_itemのpをqにビューのpをqに
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,404 +110,404 @@
|
|
110
110
|
|
111
111
|
def search
|
112
112
|
|
113
|
+
@results = @q.result.includes(:tag)
|
114
|
+
|
115
|
+
binding.pry
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def stock_item_params
|
126
|
+
|
127
|
+
params.require(:items_tag).permit(:stock_item_manufacturer, :stock_item_name, :stock_item_standard, :stock_item_strage_condition, :stock_item_description, :image, :tag_word)
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
def search_stock_item
|
134
|
+
|
135
|
+
@q = StockItem.ransack(params[:q])
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```stockitemrb
|
150
|
+
|
151
|
+
class StockItem < ApplicationRecord
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
has_one_attached :image
|
156
|
+
|
157
|
+
has_many :item_connects, dependent: :destroy
|
158
|
+
|
159
|
+
has_many :tags, through: :item_connects
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
extend ActiveHash::Associations::ActiveRecordExtensions
|
164
|
+
|
165
|
+
belongs_to :genre
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
```tagrb
|
174
|
+
|
175
|
+
class Tag < ApplicationRecord
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
has_many :item_connects
|
180
|
+
|
181
|
+
has_many :stock_items, through: :item_connects
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
```itemstagrb
|
190
|
+
|
191
|
+
include ActiveModel::Model
|
192
|
+
|
193
|
+
attr_accessor :stock_item_manufacturer, :stock_item_name, :stock_item_standard, :stock_item_strage_condition, :stock_item_description, :image, :tag_word
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
with_options presence: true do
|
198
|
+
|
199
|
+
validates :stock_item_manufacturer
|
200
|
+
|
201
|
+
validates :stock_item_name
|
202
|
+
|
203
|
+
validates :stock_item_standard
|
204
|
+
|
205
|
+
validates :stock_item_strage_condition
|
206
|
+
|
207
|
+
validates :stock_item_description
|
208
|
+
|
209
|
+
validates :image
|
210
|
+
|
211
|
+
validates :tag_word
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
def save
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
stock_item = StockItem.create(stock_item_manufacturer: stock_item_manufacturer, stock_item_name: stock_item_name, stock_item_standard: stock_item_standard, stock_item_strage_condition: stock_item_strage_condition, stock_item_description: stock_item_description, image: image)
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
tag = Tag.where(tag_word: tag_word).first_or_initialize
|
226
|
+
|
227
|
+
tag.save
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
ItemConnect.create(stock_item_id: stock_item.id, tag_id: tag.id)
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
```
|
242
|
+
|
243
|
+
```newhtml
|
244
|
+
|
245
|
+
<div class='registration-main'>
|
246
|
+
|
247
|
+
<div class='form-wrap'>
|
248
|
+
|
249
|
+
<div class="form__wrapper">
|
250
|
+
|
251
|
+
<h2 class="page-heading"> 在庫商品の投稿 </h2>
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
<%= form_with model: @stock_item, url: stock_items_path, local: true do |f| %>
|
256
|
+
|
257
|
+
<div class="field">
|
258
|
+
|
259
|
+
<%= f.label :stock_item_manufacturer, "メーカー名", class: :form_name %><br />
|
260
|
+
|
261
|
+
<%= f.text_field :stock_item_manufacturer, class: :form_text, id:"item_manufacturer" %>
|
262
|
+
|
263
|
+
</div>
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
<div class="field">
|
268
|
+
|
269
|
+
<%= f.label :stock_item_name, "商品名", class: :form_name %><br />
|
270
|
+
|
271
|
+
<%= f.text_field :stock_item_name, class: :form_text, id:"new_item_name" %>
|
272
|
+
|
273
|
+
</div>
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
<div class="field">
|
278
|
+
|
279
|
+
<%= f.label :stock_item_standard, "規格", class: :form_name %><br />
|
280
|
+
|
281
|
+
<%= f.text_field :stock_item_standard, class: :form_text, id:"item_standard" %>
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
<div class="field">
|
288
|
+
|
289
|
+
<%= f.label :stock_item_strage_condition, "保存方法", class: :form_name %><br />
|
290
|
+
|
291
|
+
<%= f.text_field :stock_item_strage_condition, class: :form_text, id:"item_strage_condition" %>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
<div class="field">
|
298
|
+
|
299
|
+
<%= f.label :stock_item_description, "商品説明", class: :form_name %><br />
|
300
|
+
|
301
|
+
<%= f.text_area :stock_item_description, class: :form__text, id:"item_description" %>
|
302
|
+
|
303
|
+
</div>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
<div class="field">
|
308
|
+
|
309
|
+
<%= f.label :tag_word, "タグ", class: :form_name %><br />
|
310
|
+
|
311
|
+
<%= f.collection_select(:tag_word, Genre.all, :name, :name, {}, {class:"form__text"}) %>
|
312
|
+
|
313
|
+
</div>
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
<div class="parallel">
|
318
|
+
|
319
|
+
<div class="field">
|
320
|
+
|
321
|
+
<%= f.label :image, "新商品の画像", class: :form_name %><br />
|
322
|
+
|
323
|
+
<%= f.file_field :image, id:"item_image", class: :form_name %>
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
<div class="actions">
|
332
|
+
|
333
|
+
<%= f.submit "保存する", class: :send, class: :form_name %>
|
334
|
+
|
335
|
+
</div>
|
336
|
+
|
337
|
+
<div id="image-list" ></div>
|
338
|
+
|
339
|
+
<% end %>
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
</div>
|
344
|
+
|
345
|
+
</div>
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
```
|
350
|
+
|
351
|
+
```indexhhml
|
352
|
+
|
353
|
+
<%# 商品の検索 %>
|
354
|
+
|
355
|
+
<div class='stock_item_search'>
|
356
|
+
|
357
|
+
<h1>
|
358
|
+
|
359
|
+
在庫商品検索
|
360
|
+
|
361
|
+
</h1>
|
362
|
+
|
363
|
+
<%= search_form_for @q, url: stock_items_search_path do |f| %>
|
364
|
+
|
365
|
+
<%= f.label :tag_word_eq, 'タグ' %>
|
366
|
+
|
367
|
+
<%= f.collection_select :stock_item_manufacturer_eq, Genre.all, :name, :name, include_blanck: '指定なし' %>
|
368
|
+
|
369
|
+
<%= f.submit '検索'%>
|
370
|
+
|
371
|
+
<% end %>
|
372
|
+
|
373
|
+
</div>
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
<%# 在庫商品一覧 %>
|
378
|
+
|
379
|
+
<div class='item-contents'>
|
380
|
+
|
381
|
+
<ul class='item-lists'>
|
382
|
+
|
383
|
+
<% @stock_items.each do |stock_item| %>
|
384
|
+
|
385
|
+
<div class='list'>
|
386
|
+
|
387
|
+
<div class='item-img-content'>
|
388
|
+
|
389
|
+
<ul class="item-index">
|
390
|
+
|
391
|
+
<li><%= stock_item.stock_item_manufacturer %></li>
|
392
|
+
|
393
|
+
<li><%= stock_item.stock_item_name %></li>
|
394
|
+
|
395
|
+
</ul>
|
396
|
+
|
397
|
+
<%= image_tag stock_item.image, class: "item-img"%>
|
398
|
+
|
399
|
+
</div>
|
400
|
+
|
401
|
+
<div class='tag'>
|
402
|
+
|
403
|
+
<li class='tag-lists'>
|
404
|
+
|
405
|
+
<% stock_item.tags.each do |tag| %>
|
406
|
+
|
407
|
+
<p><%= tag.tag_word %></p>
|
408
|
+
|
409
|
+
<% end %>
|
410
|
+
|
411
|
+
</li>
|
412
|
+
|
413
|
+
</div>
|
414
|
+
|
415
|
+
<div class="stock_item-edit">
|
416
|
+
|
417
|
+
<% if user_signed_in? && current_user.admin? %>
|
418
|
+
|
419
|
+
<%= link_to "編集する", edit_stock_item_path(stock_item.id),method: :get, class: "btn btn-outline-secondary" %>
|
420
|
+
|
421
|
+
<%= link_to "削除する", stock_item_path(stock_item.id),method: :delete, class: "btn btn-outline-secondary" %>
|
422
|
+
|
423
|
+
<% end %>
|
424
|
+
|
425
|
+
</div>
|
426
|
+
|
427
|
+
</div>
|
428
|
+
|
429
|
+
<% end %>
|
430
|
+
|
431
|
+
</ul>
|
432
|
+
|
433
|
+
</div>
|
434
|
+
|
435
|
+
<%# /在庫商品一覧 %>
|
436
|
+
|
437
|
+
```
|
438
|
+
|
439
|
+
```searchhtml
|
440
|
+
|
441
|
+
<h1>
|
442
|
+
|
443
|
+
検索結果
|
444
|
+
|
445
|
+
</h1>
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
<% if @results.length !=0 %>
|
450
|
+
|
451
|
+
<% @results.each do |result| %>
|
452
|
+
|
453
|
+
<div class='list'>
|
454
|
+
|
455
|
+
<div class='item-img-content'>
|
456
|
+
|
457
|
+
<%= image_tag stock_item.image, class: "item-img"%>
|
458
|
+
|
459
|
+
</div>
|
460
|
+
|
461
|
+
<div class='tag'>
|
462
|
+
|
463
|
+
<li class='tag-lists'>
|
464
|
+
|
465
|
+
<% stock_item.tags.each do |tag| %>
|
466
|
+
|
467
|
+
<p><%= tag.tag_word %></p>
|
468
|
+
|
469
|
+
<% end %>
|
470
|
+
|
471
|
+
</li>
|
472
|
+
|
473
|
+
</div>
|
474
|
+
|
475
|
+
</div>
|
476
|
+
|
477
|
+
<% end %>
|
478
|
+
|
479
|
+
<% else %>
|
480
|
+
|
481
|
+
該当する商品はありません
|
482
|
+
|
483
|
+
<% end %>
|
484
|
+
|
485
|
+
<br>
|
486
|
+
|
487
|
+
<%= link_to 'トップページへ戻る', root_path %>
|
488
|
+
|
489
|
+
```
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
### 試したこと
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
def search
|
504
|
+
|
113
505
|
@results = @p.result.includes(:tag)
|
114
506
|
|
115
507
|
binding.pry
|
116
508
|
|
117
509
|
end
|
118
510
|
|
119
|
-
|
120
|
-
|
121
|
-
private
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def stock_item_params
|
126
|
-
|
127
|
-
params.require(:items_tag).permit(:stock_item_manufacturer, :stock_item_name, :stock_item_standard, :stock_item_strage_condition, :stock_item_description, :image, :tag_word)
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
def search_stock_item
|
134
|
-
|
135
|
-
@p = StockItem.ransack(params[:q])
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
```
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
```stockitemrb
|
150
|
-
|
151
|
-
class StockItem < ApplicationRecord
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
has_one_attached :image
|
156
|
-
|
157
|
-
has_many :item_connects, dependent: :destroy
|
158
|
-
|
159
|
-
has_many :tags, through: :item_connects
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
extend ActiveHash::Associations::ActiveRecordExtensions
|
164
|
-
|
165
|
-
belongs_to :genre
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
```
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
```tagrb
|
174
|
-
|
175
|
-
class Tag < ApplicationRecord
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
has_many :item_connects
|
180
|
-
|
181
|
-
has_many :stock_items, through: :item_connects
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
```
|
188
|
-
|
189
|
-
```itemstagrb
|
190
|
-
|
191
|
-
include ActiveModel::Model
|
192
|
-
|
193
|
-
attr_accessor :stock_item_manufacturer, :stock_item_name, :stock_item_standard, :stock_item_strage_condition, :stock_item_description, :image, :tag_word
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
with_options presence: true do
|
198
|
-
|
199
|
-
validates :stock_item_manufacturer
|
200
|
-
|
201
|
-
validates :stock_item_name
|
202
|
-
|
203
|
-
validates :stock_item_standard
|
204
|
-
|
205
|
-
validates :stock_item_strage_condition
|
206
|
-
|
207
|
-
validates :stock_item_description
|
208
|
-
|
209
|
-
validates :image
|
210
|
-
|
211
|
-
validates :tag_word
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
def save
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
stock_item = StockItem.create(stock_item_manufacturer: stock_item_manufacturer, stock_item_name: stock_item_name, stock_item_standard: stock_item_standard, stock_item_strage_condition: stock_item_strage_condition, stock_item_description: stock_item_description, image: image)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
tag = Tag.where(tag_word: tag_word).first_or_initialize
|
226
|
-
|
227
|
-
tag.save
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
ItemConnect.create(stock_item_id: stock_item.id, tag_id: tag.id)
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
end
|
240
|
-
|
241
|
-
```
|
242
|
-
|
243
|
-
```newhtml
|
244
|
-
|
245
|
-
<div class='registration-main'>
|
246
|
-
|
247
|
-
<div class='form-wrap'>
|
248
|
-
|
249
|
-
<div class="form__wrapper">
|
250
|
-
|
251
|
-
<h2 class="page-heading"> 在庫商品の投稿 </h2>
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
<%= form_with model: @stock_item, url: stock_items_path, local: true do |f| %>
|
256
|
-
|
257
|
-
<div class="field">
|
258
|
-
|
259
|
-
<%= f.label :stock_item_manufacturer, "メーカー名", class: :form_name %><br />
|
260
|
-
|
261
|
-
<%= f.text_field :stock_item_manufacturer, class: :form_text, id:"item_manufacturer" %>
|
262
|
-
|
263
|
-
</div>
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
<div class="field">
|
268
|
-
|
269
|
-
<%= f.label :stock_item_name, "商品名", class: :form_name %><br />
|
270
|
-
|
271
|
-
<%= f.text_field :stock_item_name, class: :form_text, id:"new_item_name" %>
|
272
|
-
|
273
|
-
</div>
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
<div class="field">
|
278
|
-
|
279
|
-
<%= f.label :stock_item_standard, "規格", class: :form_name %><br />
|
280
|
-
|
281
|
-
<%= f.text_field :stock_item_standard, class: :form_text, id:"item_standard" %>
|
282
|
-
|
283
|
-
</div>
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
<div class="field">
|
288
|
-
|
289
|
-
<%= f.label :stock_item_strage_condition, "保存方法", class: :form_name %><br />
|
290
|
-
|
291
|
-
<%= f.text_field :stock_item_strage_condition, class: :form_text, id:"item_strage_condition" %>
|
292
|
-
|
293
|
-
</div>
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
<div class="field">
|
298
|
-
|
299
|
-
<%= f.label :stock_item_description, "商品説明", class: :form_name %><br />
|
300
|
-
|
301
|
-
<%= f.text_area :stock_item_description, class: :form__text, id:"item_description" %>
|
302
|
-
|
303
|
-
</div>
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
<div class="field">
|
308
|
-
|
309
|
-
<%= f.label :tag_word, "タグ", class: :form_name %><br />
|
310
|
-
|
311
|
-
<%= f.collection_select(:tag_word, Genre.all, :name, :name, {}, {class:"form__text"}) %>
|
312
|
-
|
313
|
-
</div>
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
<div class="parallel">
|
318
|
-
|
319
|
-
<div class="field">
|
320
|
-
|
321
|
-
<%= f.label :image, "新商品の画像", class: :form_name %><br />
|
322
|
-
|
323
|
-
<%= f.file_field :image, id:"item_image", class: :form_name %>
|
324
|
-
|
325
|
-
</div>
|
326
|
-
|
327
|
-
</div>
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
<div class="actions">
|
332
|
-
|
333
|
-
<%= f.submit "保存する", class: :send, class: :form_name %>
|
334
|
-
|
335
|
-
</div>
|
336
|
-
|
337
|
-
<div id="image-list" ></div>
|
338
|
-
|
339
|
-
<% end %>
|
340
|
-
|
341
|
-
</div>
|
342
|
-
|
343
|
-
</div>
|
344
|
-
|
345
|
-
</div>
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
```
|
350
|
-
|
351
|
-
```indexhhml
|
352
|
-
|
353
|
-
<%# 商品の検索 %>
|
354
|
-
|
355
|
-
<div class='stock_item_search'>
|
356
|
-
|
357
|
-
<h1>
|
358
|
-
|
359
|
-
在庫商品検索
|
360
|
-
|
361
|
-
</h1>
|
362
|
-
|
363
|
-
<%= search_form_for @p, url: stock_items_search_path do |f| %>
|
364
|
-
|
365
|
-
<%= f.label :tag_word_eq, 'タグ' %>
|
366
|
-
|
367
|
-
<%= f.collection_select :stock_item_manufacturer_eq, Genre.all, :name, :name, include_blanck: '指定なし' %>
|
368
|
-
|
369
|
-
<%= f.submit '検索'%>
|
370
|
-
|
371
|
-
<% end %>
|
372
|
-
|
373
|
-
</div>
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
<%# 在庫商品一覧 %>
|
378
|
-
|
379
|
-
<div class='item-contents'>
|
380
|
-
|
381
|
-
<ul class='item-lists'>
|
382
|
-
|
383
|
-
<% @stock_items.each do |stock_item| %>
|
384
|
-
|
385
|
-
<div class='list'>
|
386
|
-
|
387
|
-
<div class='item-img-content'>
|
388
|
-
|
389
|
-
<ul class="item-index">
|
390
|
-
|
391
|
-
<li><%= stock_item.stock_item_manufacturer %></li>
|
392
|
-
|
393
|
-
<li><%= stock_item.stock_item_name %></li>
|
394
|
-
|
395
|
-
</ul>
|
396
|
-
|
397
|
-
<%= image_tag stock_item.image, class: "item-img"%>
|
398
|
-
|
399
|
-
</div>
|
400
|
-
|
401
|
-
<div class='tag'>
|
402
|
-
|
403
|
-
<li class='tag-lists'>
|
404
|
-
|
405
|
-
<% stock_item.tags.each do |tag| %>
|
406
|
-
|
407
|
-
<p><%= tag.tag_word %></p>
|
408
|
-
|
409
|
-
<% end %>
|
410
|
-
|
411
|
-
</li>
|
412
|
-
|
413
|
-
</div>
|
414
|
-
|
415
|
-
<div class="stock_item-edit">
|
416
|
-
|
417
|
-
<% if user_signed_in? && current_user.admin? %>
|
418
|
-
|
419
|
-
<%= link_to "編集する", edit_stock_item_path(stock_item.id),method: :get, class: "btn btn-outline-secondary" %>
|
420
|
-
|
421
|
-
<%= link_to "削除する", stock_item_path(stock_item.id),method: :delete, class: "btn btn-outline-secondary" %>
|
422
|
-
|
423
|
-
<% end %>
|
424
|
-
|
425
|
-
</div>
|
426
|
-
|
427
|
-
</div>
|
428
|
-
|
429
|
-
<% end %>
|
430
|
-
|
431
|
-
</ul>
|
432
|
-
|
433
|
-
</div>
|
434
|
-
|
435
|
-
<%# /在庫商品一覧 %>
|
436
|
-
|
437
|
-
```
|
438
|
-
|
439
|
-
```searchhtml
|
440
|
-
|
441
|
-
<h1>
|
442
|
-
|
443
|
-
検索結果
|
444
|
-
|
445
|
-
</h1>
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
<% if @results.length !=0 %>
|
450
|
-
|
451
|
-
<% @results.each do |result| %>
|
452
|
-
|
453
|
-
<div class='list'>
|
454
|
-
|
455
|
-
<div class='item-img-content'>
|
456
|
-
|
457
|
-
<%= image_tag stock_item.image, class: "item-img"%>
|
458
|
-
|
459
|
-
</div>
|
460
|
-
|
461
|
-
<div class='tag'>
|
462
|
-
|
463
|
-
<li class='tag-lists'>
|
464
|
-
|
465
|
-
<% stock_item.tags.each do |tag| %>
|
466
|
-
|
467
|
-
<p><%= tag.tag_word %></p>
|
468
|
-
|
469
|
-
<% end %>
|
470
|
-
|
471
|
-
</li>
|
472
|
-
|
473
|
-
</div>
|
474
|
-
|
475
|
-
</div>
|
476
|
-
|
477
|
-
<% end %>
|
478
|
-
|
479
|
-
<% else %>
|
480
|
-
|
481
|
-
該当する商品はありません
|
482
|
-
|
483
|
-
<% end %>
|
484
|
-
|
485
|
-
<br>
|
486
|
-
|
487
|
-
<%= link_to 'トップページへ戻る', root_path %>
|
488
|
-
|
489
|
-
```
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
### 試したこと
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
def search
|
504
|
-
|
505
|
-
@results = @p.result.includes(:tag)
|
506
|
-
|
507
|
-
binding.pry
|
508
|
-
|
509
|
-
end
|
510
|
-
|
511
511
|
ここでbinding.pryで止めると
|
512
512
|
|
513
513
|
pry(#<StockItemsController>)> params
|
1
ビューの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -240,6 +240,256 @@
|
|
240
240
|
|
241
241
|
```
|
242
242
|
|
243
|
+
```newhtml
|
244
|
+
|
245
|
+
<div class='registration-main'>
|
246
|
+
|
247
|
+
<div class='form-wrap'>
|
248
|
+
|
249
|
+
<div class="form__wrapper">
|
250
|
+
|
251
|
+
<h2 class="page-heading"> 在庫商品の投稿 </h2>
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
<%= form_with model: @stock_item, url: stock_items_path, local: true do |f| %>
|
256
|
+
|
257
|
+
<div class="field">
|
258
|
+
|
259
|
+
<%= f.label :stock_item_manufacturer, "メーカー名", class: :form_name %><br />
|
260
|
+
|
261
|
+
<%= f.text_field :stock_item_manufacturer, class: :form_text, id:"item_manufacturer" %>
|
262
|
+
|
263
|
+
</div>
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
<div class="field">
|
268
|
+
|
269
|
+
<%= f.label :stock_item_name, "商品名", class: :form_name %><br />
|
270
|
+
|
271
|
+
<%= f.text_field :stock_item_name, class: :form_text, id:"new_item_name" %>
|
272
|
+
|
273
|
+
</div>
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
<div class="field">
|
278
|
+
|
279
|
+
<%= f.label :stock_item_standard, "規格", class: :form_name %><br />
|
280
|
+
|
281
|
+
<%= f.text_field :stock_item_standard, class: :form_text, id:"item_standard" %>
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
<div class="field">
|
288
|
+
|
289
|
+
<%= f.label :stock_item_strage_condition, "保存方法", class: :form_name %><br />
|
290
|
+
|
291
|
+
<%= f.text_field :stock_item_strage_condition, class: :form_text, id:"item_strage_condition" %>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
<div class="field">
|
298
|
+
|
299
|
+
<%= f.label :stock_item_description, "商品説明", class: :form_name %><br />
|
300
|
+
|
301
|
+
<%= f.text_area :stock_item_description, class: :form__text, id:"item_description" %>
|
302
|
+
|
303
|
+
</div>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
<div class="field">
|
308
|
+
|
309
|
+
<%= f.label :tag_word, "タグ", class: :form_name %><br />
|
310
|
+
|
311
|
+
<%= f.collection_select(:tag_word, Genre.all, :name, :name, {}, {class:"form__text"}) %>
|
312
|
+
|
313
|
+
</div>
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
<div class="parallel">
|
318
|
+
|
319
|
+
<div class="field">
|
320
|
+
|
321
|
+
<%= f.label :image, "新商品の画像", class: :form_name %><br />
|
322
|
+
|
323
|
+
<%= f.file_field :image, id:"item_image", class: :form_name %>
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
<div class="actions">
|
332
|
+
|
333
|
+
<%= f.submit "保存する", class: :send, class: :form_name %>
|
334
|
+
|
335
|
+
</div>
|
336
|
+
|
337
|
+
<div id="image-list" ></div>
|
338
|
+
|
339
|
+
<% end %>
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
</div>
|
344
|
+
|
345
|
+
</div>
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
```
|
350
|
+
|
351
|
+
```indexhhml
|
352
|
+
|
353
|
+
<%# 商品の検索 %>
|
354
|
+
|
355
|
+
<div class='stock_item_search'>
|
356
|
+
|
357
|
+
<h1>
|
358
|
+
|
359
|
+
在庫商品検索
|
360
|
+
|
361
|
+
</h1>
|
362
|
+
|
363
|
+
<%= search_form_for @p, url: stock_items_search_path do |f| %>
|
364
|
+
|
365
|
+
<%= f.label :tag_word_eq, 'タグ' %>
|
366
|
+
|
367
|
+
<%= f.collection_select :stock_item_manufacturer_eq, Genre.all, :name, :name, include_blanck: '指定なし' %>
|
368
|
+
|
369
|
+
<%= f.submit '検索'%>
|
370
|
+
|
371
|
+
<% end %>
|
372
|
+
|
373
|
+
</div>
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
<%# 在庫商品一覧 %>
|
378
|
+
|
379
|
+
<div class='item-contents'>
|
380
|
+
|
381
|
+
<ul class='item-lists'>
|
382
|
+
|
383
|
+
<% @stock_items.each do |stock_item| %>
|
384
|
+
|
385
|
+
<div class='list'>
|
386
|
+
|
387
|
+
<div class='item-img-content'>
|
388
|
+
|
389
|
+
<ul class="item-index">
|
390
|
+
|
391
|
+
<li><%= stock_item.stock_item_manufacturer %></li>
|
392
|
+
|
393
|
+
<li><%= stock_item.stock_item_name %></li>
|
394
|
+
|
395
|
+
</ul>
|
396
|
+
|
397
|
+
<%= image_tag stock_item.image, class: "item-img"%>
|
398
|
+
|
399
|
+
</div>
|
400
|
+
|
401
|
+
<div class='tag'>
|
402
|
+
|
403
|
+
<li class='tag-lists'>
|
404
|
+
|
405
|
+
<% stock_item.tags.each do |tag| %>
|
406
|
+
|
407
|
+
<p><%= tag.tag_word %></p>
|
408
|
+
|
409
|
+
<% end %>
|
410
|
+
|
411
|
+
</li>
|
412
|
+
|
413
|
+
</div>
|
414
|
+
|
415
|
+
<div class="stock_item-edit">
|
416
|
+
|
417
|
+
<% if user_signed_in? && current_user.admin? %>
|
418
|
+
|
419
|
+
<%= link_to "編集する", edit_stock_item_path(stock_item.id),method: :get, class: "btn btn-outline-secondary" %>
|
420
|
+
|
421
|
+
<%= link_to "削除する", stock_item_path(stock_item.id),method: :delete, class: "btn btn-outline-secondary" %>
|
422
|
+
|
423
|
+
<% end %>
|
424
|
+
|
425
|
+
</div>
|
426
|
+
|
427
|
+
</div>
|
428
|
+
|
429
|
+
<% end %>
|
430
|
+
|
431
|
+
</ul>
|
432
|
+
|
433
|
+
</div>
|
434
|
+
|
435
|
+
<%# /在庫商品一覧 %>
|
436
|
+
|
437
|
+
```
|
438
|
+
|
439
|
+
```searchhtml
|
440
|
+
|
441
|
+
<h1>
|
442
|
+
|
443
|
+
検索結果
|
444
|
+
|
445
|
+
</h1>
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
<% if @results.length !=0 %>
|
450
|
+
|
451
|
+
<% @results.each do |result| %>
|
452
|
+
|
453
|
+
<div class='list'>
|
454
|
+
|
455
|
+
<div class='item-img-content'>
|
456
|
+
|
457
|
+
<%= image_tag stock_item.image, class: "item-img"%>
|
458
|
+
|
459
|
+
</div>
|
460
|
+
|
461
|
+
<div class='tag'>
|
462
|
+
|
463
|
+
<li class='tag-lists'>
|
464
|
+
|
465
|
+
<% stock_item.tags.each do |tag| %>
|
466
|
+
|
467
|
+
<p><%= tag.tag_word %></p>
|
468
|
+
|
469
|
+
<% end %>
|
470
|
+
|
471
|
+
</li>
|
472
|
+
|
473
|
+
</div>
|
474
|
+
|
475
|
+
</div>
|
476
|
+
|
477
|
+
<% end %>
|
478
|
+
|
479
|
+
<% else %>
|
480
|
+
|
481
|
+
該当する商品はありません
|
482
|
+
|
483
|
+
<% end %>
|
484
|
+
|
485
|
+
<br>
|
486
|
+
|
487
|
+
<%= link_to 'トップページへ戻る', root_path %>
|
488
|
+
|
489
|
+
```
|
490
|
+
|
491
|
+
|
492
|
+
|
243
493
|
|
244
494
|
|
245
495
|
|