質問編集履歴
2
追加説明
title
CHANGED
File without changes
|
body
CHANGED
@@ -35,7 +35,7 @@
|
|
35
35
|
validates :image_url, presence: true, if: :main_image?
|
36
36
|
|
37
37
|
def main_image?
|
38
|
-
|
38
|
+
status == "main_image"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
```
|
@@ -56,4 +56,9 @@
|
|
56
56
|
|
57
57
|
```
|
58
58
|
このようにimage_urlが入ってきません。。。
|
59
|
-
テストを通りません。
|
59
|
+
テストを通りません。
|
60
|
+
ちなみに、
|
61
|
+
```
|
62
|
+
[1] pry(#<RSpec::ExampleGroups::CaptureImage::MainImage>)> capture_image.status = "sub_image"
|
63
|
+
```
|
64
|
+
とすると、statusは普通に1に変わります。なぜかimage_urlだけ追加・変更不可です。
|
1
capture_imageモデルの実装コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,17 +27,21 @@
|
|
27
27
|
association :prototype
|
28
28
|
end
|
29
29
|
```
|
30
|
-
(enumでmain_imageかsub_imageか管理しています)
|
31
|
-
###試したこと
|
32
30
|
```ruby
|
31
|
+
class CaptureImage < ActiveRecord::Base
|
32
|
+
belongs_to :prototype
|
33
|
+
enum satus: {main_image: 0, sub_image: 1}
|
34
|
+
mount_uploader :image_url, ImageUploader
|
35
|
+
validates :image_url, presence: true, if: :main_image?
|
36
|
+
|
37
|
+
def main_image?
|
33
|
-
|
38
|
+
satus == "main_image"
|
34
|
-
it "valid with main_image" do
|
35
|
-
capture_image = build(:capture_image, image_url:"rrrrr.png")
|
36
|
-
binding.pry
|
37
|
-
expect(capture_image).to be_valid
|
38
|
-
end
|
39
39
|
end
|
40
|
+
end
|
40
41
|
```
|
42
|
+
※capture_imageモデル追加しました。(修正)
|
43
|
+
(enumでmain_imageかsub_imageか管理しています)
|
44
|
+
###試したこと
|
41
45
|
上記のように実装して、binding.pryが起きたところで止めて確認しても、
|
42
46
|
```
|
43
47
|
#<CaptureImage:0x007fe1d98d4c68 id: nil, image_url: nil, prototype_id: 60, created_at: nil, updated_at: nil, satus: 0>
|