質問編集履歴
2
説明漏れがあったので修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -106,21 +106,57 @@
|
|
106
106
|
|
107
107
|
### 試したこと
|
108
108
|
|
109
|
+
```
|
110
|
+
|
109
|
-
|
111
|
+
app/decorators/concerns/fruit_decorator.rb
|
110
112
|
|
111
113
|
|
112
114
|
|
115
|
+
module FruitDecorator
|
116
|
+
|
117
|
+
extend ActiveSupport::Concern
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
def full_name
|
122
|
+
|
113
|
-
|
123
|
+
"#{first_name} #{last_name}"
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
114
128
|
|
115
129
|
```
|
116
130
|
|
117
|
-
|
131
|
+
上記、前提・実現したいことに記載のようにfruit_decorator.rbを作成しfruit.rbからfruit_decorator.rbにfull_nameメソッドを移しました。
|
118
132
|
|
119
|
-
app/decorators/grape_decorator.rb
|
120
|
-
|
121
|
-
|
133
|
+
その後、下記のようにviewでfull_nameメソッドを使用しましたが、エラーが出てしまいdecorator層に定義したメソッドを呼び出すことができませんでした。
|
122
134
|
|
123
135
|
```
|
136
|
+
|
137
|
+
app/views/apples/index.html.erb
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<% @apples.each do |apple| %>
|
142
|
+
|
143
|
+
<%= apple.full_name %><br>
|
144
|
+
|
145
|
+
<% end %>
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
エラー文
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
ActionView::Template::Error - undefined method `full_name'
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
|
124
160
|
|
125
161
|
|
126
162
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,7 +70,7 @@
|
|
70
70
|
|
71
71
|
class Apple < ApplicationRecord
|
72
72
|
|
73
|
-
include
|
73
|
+
include Fruit
|
74
74
|
|
75
75
|
end
|
76
76
|
|
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
class Grape < ApplicationRecord
|
86
86
|
|
87
|
-
include
|
87
|
+
include Fruit
|
88
88
|
|
89
89
|
end
|
90
90
|
|
@@ -98,7 +98,7 @@
|
|
98
98
|
|
99
99
|
class Banana < ApplicationRecord
|
100
100
|
|
101
|
-
include
|
101
|
+
include Fruit
|
102
102
|
|
103
103
|
end
|
104
104
|
|