質問編集履歴
1
想定しているエラーと、itemモデルを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
|
6
6
|
### 実現したいこと
|
7
7
|
|
8
|
-
createアクションでデータの保存に失敗した場合、出品画面に戻り、エラーメッセージを表示したい
|
8
|
+
・createアクションでデータの保存に失敗した場合、出品画面に戻り、エラーメッセージを表示したい
|
9
|
+
・フォームに入力されていない項目があった場合、validatesに引っかかって、"〜can`t be blank"などのエラーメッセージが出ることを想定しています。
|
9
10
|
|
10
11
|
### 発生している問題・エラーメッセージ
|
11
12
|
|
@@ -226,6 +227,28 @@
|
|
226
227
|
[Webpacker] Everything's up-to-date. Nothing to do
|
227
228
|
Completed 200 OK in 110ms (Views: 97.6ms | ActiveRecord: 0.0ms | Allocations: 30869)
|
228
229
|
```
|
230
|
+
item.rb
|
231
|
+
itemモデル(varidates)
|
232
|
+
```
|
233
|
+
class Item < ApplicationRecord
|
234
|
+
validates :title, presence: true
|
235
|
+
validates :price, numericality:{greater_than_or_equal_to: 300, less_than_or_equal_to: 9999999}
|
236
|
+
validates :fee_id, numericality: { other_than: 1 , message: "can't be blank"}
|
237
|
+
validates :description, presence: true
|
238
|
+
validates :category_id, numericality: { other_than: 1 , message: "can't be blank"}
|
239
|
+
validates :condition_id, numericality: { other_than: 1 , message: "can't be blank"}
|
240
|
+
validates :from_id, numericality: { other_than: 1 , message: "can't be blank"}
|
241
|
+
validates :ship_date_id, numericality: { other_than: 1 , message: "can't be blank"}
|
242
|
+
has_one_attached :image
|
243
|
+
|
244
|
+
extend ActiveHash::Associations::ActiveRecordExtensions
|
245
|
+
belongs_to :category
|
246
|
+
belongs_to :condition
|
247
|
+
belongs_to :fee
|
248
|
+
belongs_to :from
|
249
|
+
belongs_to :ship
|
250
|
+
end
|
251
|
+
```
|
229
252
|
### 試したこと
|
230
253
|
・出品画面(new.html.erb)のフォームを正しく入力をすれば保存できることは確認できています。(Sequel Proでデータベースを直接確認しています。)
|
231
254
|
|