質問編集履歴

3

createメソッドのcreateをnewに変更

2020/10/23 01:24

投稿

yozakura10
yozakura10

スコア8

test CHANGED
File without changes
test CHANGED
@@ -162,7 +162,7 @@
162
162
 
163
163
  def create
164
164
 
165
- @prototype = Prototype.create(prototype_params)
165
+ @prototype = Prototype.*new*(prototype_params)
166
166
 
167
167
  if @prototype.save
168
168
 

2

saveに!をつけたところこのようなエラー文が出ました、

2020/10/23 01:24

投稿

yozakura10
yozakura10

スコア8

test CHANGED
File without changes
test CHANGED
@@ -20,41 +20,81 @@
20
20
 
21
21
 
22
22
 
23
- ターミナルのエラー文です
24
-
25
- ```
26
-
27
- Started POST "/prototypes" for ::1 at 2020-10-22 23:26:18 +0900
28
-
29
- (0.2ms) SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
30
-
31
- Processing by PrototypesController#create as HTML
32
-
33
- Parameters: {"authenticity_token"=>"ztX8p9+qIFuWU2w/gpWI45xQf3Rh1OCywI2OUdYpTaOEwVquHTnCBoe9B971OA7XmJvBlGjtVplKKV0BErOaWQ==", "prototype"=>{"title"=>"aaa", "catct_copy"=>"aaa", "concept"=>"aaa"}, "commit"=>"保存する"}
34
-
35
- User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
36
-
37
- (0.2ms) BEGIN
38
-
39
- app/controllers/prototypes_controller.rb:12:in `create'
40
-
41
- User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
42
-
43
- app/controllers/prototypes_controller.rb:12:in `create'
44
-
45
- (0.1ms) ROLLBACK
46
-
47
- ↳ app/controllers/prototypes_controller.rb:12:in `create'
48
-
49
- Rendering prototypes/new.html.erb within layouts/application
50
-
51
- Rendered prototypes/_form.html.erb (Duration: 0.7ms | Allocations: 546)
52
-
53
- Rendered prototypes/new.html.erb within layouts/application (Duration: 0.8ms | Allocations: 617)
54
-
55
- [Webpacker] Everything's up-to-date. Nothing to do
56
-
57
- Completed 200 OK in 26ms (Views: 20.3ms | ActiveRecord: 0.7ms | Allocations: 14372)
23
+ エラー文です
24
+
25
+ ```
26
+
27
+ ActiveRecord::RecordInvalid in PrototypesController#create
28
+
29
+ Validation failed: Image can't be blank
30
+
31
+ Extracted source (around line #13):
32
+
33
+
34
+
35
+ def create
36
+
37
+ @prototype = Prototype.create(prototype_params)
38
+
39
+ if @prototype.save!
40
+
41
+ redirect_to root_path
42
+
43
+ else
44
+
45
+ render :new
46
+
47
+
48
+
49
+ Rails.root: /Users/kamiyaryota/Desktop/projects/protospace-31035
50
+
51
+
52
+
53
+ Application Trace | Framework Trace | Full Trace
54
+
55
+ app/controllers/prototypes_controller.rb:13:in `create'
56
+
57
+ Request
58
+
59
+ Parameters:
60
+
61
+
62
+
63
+ {"authenticity_token"=>"X/fnWlXUYadtT1MdGuTVyinnpu2B/riCk3iqiFXD3HMV40FTl0eD+nyhOPxtSVP+LSwYDYjHDqkZ3HnYkVkLiQ==",
64
+
65
+ "prototype"=>
66
+
67
+ {"title"=>"aaa",
68
+
69
+ "catct_copy"=>"aaa",
70
+
71
+ "concept"=>"aaaa",
72
+
73
+ "image"=>
74
+
75
+ #<ActionDispatch::Http::UploadedFile:0x00007fe8ead15300
76
+
77
+ @content_type="image/png",
78
+
79
+ @headers="Content-Disposition: form-data; name=\"prototype[image]\"; filename=\"test_image.png\"\r\n" + "Content-Type: image/png\r\n",
80
+
81
+ @original_filename="test_image.png",
82
+
83
+ @tempfile=#<File:/var/folders/4y/hbjp90hd2rl1bfd0m4kczr3m0000gn/T/RackMultipart20201023-27843-i4n9cr.png>>},
84
+
85
+ "commit"=>"保存する"}
86
+
87
+ Toggle session dump
88
+
89
+ Toggle env dump
90
+
91
+ Response
92
+
93
+ Headers:
94
+
95
+
96
+
97
+ None
58
98
 
59
99
  ```
60
100
 
@@ -160,7 +200,9 @@
160
200
 
161
201
 
162
202
 
163
- model.rbです
203
+ model
204
+
205
+ prototype.rbです
164
206
 
165
207
  ```ryby
166
208
 
@@ -192,6 +234,44 @@
192
234
 
193
235
 
194
236
 
237
+ model
238
+
239
+ user.rbです
240
+
241
+
242
+
243
+ ```ruby
244
+
245
+ class User < ApplicationRecord
246
+
247
+ # Include default devise modules. Others available are:
248
+
249
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
250
+
251
+ devise :database_authenticatable, :registerable,
252
+
253
+ :recoverable, :rememberable, :validatable
254
+
255
+
256
+
257
+ has_many :prototypes
258
+
259
+ has_many :comments
260
+
261
+
262
+
263
+ validates :name, presence: true
264
+
265
+ validates :profile, presence: true
266
+
267
+ validates :occupation, presence: true
268
+
269
+ validates :position, presence: true
270
+
271
+ end
272
+
273
+ ```
274
+
195
275
 
196
276
 
197
277
  *投稿ページです*

1

codeの修正

2020/10/23 01:20

投稿

yozakura10
yozakura10

スコア8

test CHANGED
File without changes
test CHANGED
@@ -54,7 +54,9 @@
54
54
 
55
55
  [Webpacker] Everything's up-to-date. Nothing to do
56
56
 
57
- Completed 200 OK in 26ms (Views: 20.3ms | ActiveRecord: 0.7ms | Allocations: 14372)```
57
+ Completed 200 OK in 26ms (Views: 20.3ms | ActiveRecord: 0.7ms | Allocations: 14372)
58
+
59
+ ```
58
60
 
59
61
 
60
62