質問編集履歴

2

itemモデルを付け加えました。

2020/12/11 03:34

投稿

murohi-08
murohi-08

スコア12

test CHANGED
File without changes
test CHANGED
@@ -416,6 +416,74 @@
416
416
 
417
417
 
418
418
 
419
+ ```ここに言語を入力
420
+
421
+ app/models/item.rb
422
+
423
+
424
+
425
+ class Item < ApplicationRecord
426
+
427
+ belongs_to :user
428
+
429
+ has_one :purchase_history
430
+
431
+ has_one_attached :image
432
+
433
+ extend ActiveHash::Associations::ActiveRecordExtensions
434
+
435
+ belongs_to_active_hash :prefecture
436
+
437
+ belongs_to_active_hash :prepare
438
+
439
+ belongs_to_active_hash :postage
440
+
441
+ belongs_to_active_hash :item_condition
442
+
443
+ belongs_to_active_hash :category
444
+
445
+
446
+
447
+ with_options presence: true do
448
+
449
+ validates :image
450
+
451
+ validates :name
452
+
453
+ validates :introduction
454
+
455
+ validates :price
456
+
457
+ end
458
+
459
+ validates :price, numericality: { greater_than_or_equal_to: 300, less_than_or_equal_to: 9999999, message: "Out of setting range"}
460
+
461
+ validates :price, numericality: { only_integer: true, message: "Half-width number." }
462
+
463
+
464
+
465
+ with_options numericality: { other_than: 0, message: "Select" } do
466
+
467
+ validates :item_condition_id
468
+
469
+ validates :postage_id
470
+
471
+ validates :prefecture_id
472
+
473
+ validates :prepare_id
474
+
475
+ validates :category_id
476
+
477
+ end
478
+
479
+
480
+
481
+ end
482
+
483
+ ```
484
+
485
+
486
+
419
487
  試したこと
420
488
 
421
489
  画像のコードを記述する際には@user_item.imageをimage_tagの中に入れましたが、引数エラーが出ます。

1

Formオブジェクトパターンを使っています。

2020/12/11 03:34

投稿

murohi-08
murohi-08

スコア12

test CHANGED
File without changes
test CHANGED
@@ -422,6 +422,6 @@
422
422
 
423
423
  価格に関するコードは@user_item.priceですが、@を抜いてもエラーにはならないのですが何も表示されません。
424
424
 
425
- 配送料負担のところは@user_item.prepare.nameですが、nameを_idにするとエラーは出ませんが表示がされません。
425
+ 配送料負担のところは@user_item.prepare.nameはメソッド空のエラー表示され、nameを_idにするとエラーは出ませんが表示がされません。
426
426
 
427
427
  おそらくはフォームオブジェクトのファイルに問題があると思っているのですが、原因が特定できません。