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

質問編集履歴

2

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

2020/12/11 03:34

投稿

murohi-08
murohi-08

スコア12

title CHANGED
File without changes
body CHANGED
@@ -207,6 +207,40 @@
207
207
  end
208
208
  ```
209
209
 
210
+ ```ここに言語を入力
211
+ app/models/item.rb
212
+
213
+ class Item < ApplicationRecord
214
+ belongs_to :user
215
+ has_one :purchase_history
216
+ has_one_attached :image
217
+ extend ActiveHash::Associations::ActiveRecordExtensions
218
+ belongs_to_active_hash :prefecture
219
+ belongs_to_active_hash :prepare
220
+ belongs_to_active_hash :postage
221
+ belongs_to_active_hash :item_condition
222
+ belongs_to_active_hash :category
223
+
224
+ with_options presence: true do
225
+ validates :image
226
+ validates :name
227
+ validates :introduction
228
+ validates :price
229
+ end
230
+ validates :price, numericality: { greater_than_or_equal_to: 300, less_than_or_equal_to: 9999999, message: "Out of setting range"}
231
+ validates :price, numericality: { only_integer: true, message: "Half-width number." }
232
+
233
+ with_options numericality: { other_than: 0, message: "Select" } do
234
+ validates :item_condition_id
235
+ validates :postage_id
236
+ validates :prefecture_id
237
+ validates :prepare_id
238
+ validates :category_id
239
+ end
240
+
241
+ end
242
+ ```
243
+
210
244
  試したこと
211
245
  画像のコードを記述する際には@user_item.imageをimage_tagの中に入れましたが、引数エラーが出ます。
212
246
  価格に関するコードは@user_item.priceですが、@を抜いてもエラーにはならないのですが何も表示されません。

1

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

2020/12/11 03:34

投稿

murohi-08
murohi-08

スコア12

title CHANGED
File without changes
body CHANGED
@@ -210,5 +210,5 @@
210
210
  試したこと
211
211
  画像のコードを記述する際には@user_item.imageをimage_tagの中に入れましたが、引数エラーが出ます。
212
212
  価格に関するコードは@user_item.priceですが、@を抜いてもエラーにはならないのですが何も表示されません。
213
- 配送料負担のところは@user_item.prepare.nameですが、nameを_idにするとエラーは出ませんが表示がされません。
213
+ 配送料負担のところは@user_item.prepare.nameはメソッド空のエラー表示され、nameを_idにするとエラーは出ませんが表示がされません。
214
214
  おそらくはフォームオブジェクトのファイルに問題があると思っているのですが、原因が特定できません。