質問編集履歴
2
説明漏れがあったので修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -52,15 +52,33 @@
|
|
52
52
|
end
|
53
53
|
```
|
54
54
|
### 試したこと
|
55
|
+
```
|
55
|
-
|
56
|
+
app/decorators/concerns/fruit_decorator.rb
|
56
57
|
|
58
|
+
module FruitDecorator
|
59
|
+
extend ActiveSupport::Concern
|
60
|
+
|
61
|
+
def full_name
|
57
|
-
|
62
|
+
"#{first_name} #{last_name}"
|
63
|
+
end
|
64
|
+
end
|
58
65
|
```
|
59
|
-
app/decorators/apple_decorator.rb
|
60
|
-
app/decorators/grape_decorator.rb
|
61
|
-
|
66
|
+
上記、前提・実現したいことに記載のようにfruit_decorator.rbを作成しfruit.rbからfruit_decorator.rbにfull_nameメソッドを移しました。
|
67
|
+
その後、下記のようにviewでfull_nameメソッドを使用しましたが、エラーが出てしまいdecorator層に定義したメソッドを呼び出すことができませんでした。
|
62
68
|
```
|
69
|
+
app/views/apples/index.html.erb
|
63
70
|
|
71
|
+
<% @apples.each do |apple| %>
|
72
|
+
<%= apple.full_name %><br>
|
73
|
+
<% end %>
|
74
|
+
```
|
75
|
+
```
|
76
|
+
エラー文
|
77
|
+
|
78
|
+
ActionView::Template::Error - undefined method `full_name'
|
79
|
+
```
|
80
|
+
|
81
|
+
|
64
82
|
### 補足情報(FW/ツールのバージョンなど)
|
65
83
|
|
66
84
|
* Rails 6.0.3.5
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,21 +34,21 @@
|
|
34
34
|
app/models/apple.rb
|
35
35
|
|
36
36
|
class Apple < ApplicationRecord
|
37
|
-
include
|
37
|
+
include Fruit
|
38
38
|
end
|
39
39
|
```
|
40
40
|
```
|
41
41
|
app/models/grape.rb
|
42
42
|
|
43
43
|
class Grape < ApplicationRecord
|
44
|
-
include
|
44
|
+
include Fruit
|
45
45
|
end
|
46
46
|
```
|
47
47
|
```
|
48
48
|
app/models/banana.rb
|
49
49
|
|
50
50
|
class Banana < ApplicationRecord
|
51
|
-
include
|
51
|
+
include Fruit
|
52
52
|
end
|
53
53
|
```
|
54
54
|
### 試したこと
|