質問編集履歴
5
show追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,6 +20,36 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
```ruby
|
24
|
+
|
25
|
+
#show.html.erb
|
26
|
+
|
27
|
+
<div class="container">
|
28
|
+
|
29
|
+
<div class ="row">
|
30
|
+
|
31
|
+
<div class="col-md-6">
|
32
|
+
|
33
|
+
<p style="font-weight:bold;font-size:1.2rem;">
|
34
|
+
|
35
|
+
場所:<%= @product.adviser.user.address %>
|
36
|
+
|
37
|
+
</p>
|
38
|
+
|
39
|
+
</div><!--col-->
|
40
|
+
|
41
|
+
</div><!--row-->
|
42
|
+
|
43
|
+
</div><!--container -->
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
23
53
|
`controller`は以下の通り記載しています。
|
24
54
|
|
25
55
|
```ruby
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -187,3 +187,69 @@
|
|
187
187
|
|
188
188
|
|
189
189
|
```
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
`binding.pry`の結果は以下の通りです。addressにしっかり入っていることが確認できました。
|
194
|
+
|
195
|
+
```
|
196
|
+
|
197
|
+
[1] pry(#<#<Class:0x007fdaa123d308>>)> p.adviser
|
198
|
+
|
199
|
+
=> #<Adviser:0x007fda9db9a878
|
200
|
+
|
201
|
+
id: 1,
|
202
|
+
|
203
|
+
user_id: 1,
|
204
|
+
|
205
|
+
profile: "109でショップ店員してます!ギャル風アイメイクが得意♩",
|
206
|
+
|
207
|
+
occupation: nil,
|
208
|
+
|
209
|
+
created_at: Sun, 22 Jan 2017 17:25:10 JST +09:00,
|
210
|
+
|
211
|
+
updated_at: Sun, 22 Jan 2017 17:25:10 JST +09:00>
|
212
|
+
|
213
|
+
[2] pry(#<#<Class:0x007fdaa123d308>>)> p.adviser.user
|
214
|
+
|
215
|
+
=> #<User:0x007fda9db32520
|
216
|
+
|
217
|
+
id: 1,
|
218
|
+
|
219
|
+
email: "yuu.sato@example.com",
|
220
|
+
|
221
|
+
email_for_index: "yuu.sato@example.com",
|
222
|
+
|
223
|
+
family_name: "佐藤",
|
224
|
+
|
225
|
+
given_name: "悠",
|
226
|
+
|
227
|
+
family_name_kana: "sato",
|
228
|
+
|
229
|
+
given_name_kana: "yuu",
|
230
|
+
|
231
|
+
user_name: "mitsuo",
|
232
|
+
|
233
|
+
address: "栃木県",
|
234
|
+
|
235
|
+
hashed_password:
|
236
|
+
|
237
|
+
"$2a$10$h2IbGgkaimCUYM.G37RYQe88lDpZO6d4gQWHzicVQotx4gZ37bcS2",
|
238
|
+
|
239
|
+
start_date: Fri, 14 Oct 2016,
|
240
|
+
|
241
|
+
end_date: nil,
|
242
|
+
|
243
|
+
suspended: false,
|
244
|
+
|
245
|
+
created_at: Sun, 22 Jan 2017 17:25:08 JST +09:00,
|
246
|
+
|
247
|
+
updated_at: Sun, 22 Jan 2017 17:25:08 JST +09:00>
|
248
|
+
|
249
|
+
[3] pry(#<#<Class:0x007fdaa123d308>>)> p.adviser.user.address
|
250
|
+
|
251
|
+
=> "栃木県"
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
```
|
3
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -155,3 +155,35 @@
|
|
155
155
|
Completed 200 OK in 24ms (Views: 0.8ms | ActiveRecord: 12.4ms)
|
156
156
|
|
157
157
|
```
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
addressが空で無いこと、確認取れております。
|
162
|
+
|
163
|
+
```ここに言語を入力
|
164
|
+
|
165
|
+
irb(main):008:0* product = Product.find(1)
|
166
|
+
|
167
|
+
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
|
168
|
+
|
169
|
+
=> #<Product id: 1, adviser_id: 1, price: 2000, required_time: 1, title: "ファンデーションの基礎教えます", parts: "チーク", situation: "仕事", makeupkit: "自分の道具不要(アドバイザーの物を使用)", makeupkit_explain: "おすすめの道具等お教えします。", memo: "就職活動で重要な知的さと清楚さを第一印象として与える出すメイク教えます。で買いました。", place: "東京都内ならどこでも", place_memo: "山下公園のベンチを考えています。", posted_at: "2017-01-13 08:25:09", data: nil, created_at: "2017-01-22 08:25:09", updated_at: "2017-01-22 08:25:09", makeimg: nil, makeimgs: [], makeimg_two: nil, makeimg_three: nil>
|
170
|
+
|
171
|
+
irb(main):009:0> adviser = product.adviser
|
172
|
+
|
173
|
+
Adviser Load (0.4ms) SELECT "advisers".* FROM "advisers" WHERE "advisers"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
|
174
|
+
|
175
|
+
=> #<Adviser id: 1, user_id: 1, profile: "109でショップ店員してます!ギャル風アイメイクが得意♩", occupation: nil, created_at: "2017-01-22 08:25:10", updated_at: "2017-01-22 08:25:10">
|
176
|
+
|
177
|
+
irb(main):010:0> user = adviser.user
|
178
|
+
|
179
|
+
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
|
180
|
+
|
181
|
+
=> #<User id: 1, email: "yuu.sato@example.com", email_for_index: "yuu.sato@example.com", family_name: "佐藤", given_name: "悠", family_name_kana: "sato", given_name_kana: "yuu", user_name: "mitsuo", address: "栃木県", hashed_password: "$2a$10$h2IbGgkaimCUYM.G37RYQe88lDpZO6d4gQWHzicVQot...", start_date: "2016-10-14", end_date: nil, suspended: false, created_at: "2017-01-22 08:25:08", updated_at: "2017-01-22 08:25:08">
|
182
|
+
|
183
|
+
irb(main):011:0> user.address
|
184
|
+
|
185
|
+
=> "栃木県"
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
```
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
`index`メソッドでは`@product.adviser.user.address`が機能するのですが、`show`メソッドでは`undefined method "address"`が出てしまいます。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
*正確には、indexメソッドではに以下にて呼び出しています。
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
|
9
|
+
<% @products.each do |p| %>
|
10
|
+
|
11
|
+
<%= p.adviser.user.address %>
|
12
|
+
|
13
|
+
<% end%>
|
14
|
+
|
15
|
+
```
|
2
16
|
|
3
17
|
|
4
18
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -109,3 +109,35 @@
|
|
109
109
|
ActionView::Template::Error (undefined method `address' for nil:NilClass):
|
110
110
|
|
111
111
|
```
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
`@product.adviser.user.address`から`address`を抜いた`@product.adviser.user`だと画面は表示されます(エラーは出ません)
|
116
|
+
|
117
|
+
ログは以下の通りです。
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```ここに言語を入力
|
122
|
+
|
123
|
+
Started GET "/user/users/1.jpg" for ::1 at 2017-01-22 16:00:33 +0900
|
124
|
+
|
125
|
+
Processing by User::UsersController#show as JPEG
|
126
|
+
|
127
|
+
Parameters: {"id"=>"1"}
|
128
|
+
|
129
|
+
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
|
130
|
+
|
131
|
+
Adviser Load (0.7ms) SELECT "advisers".* FROM "advisers" WHERE "advisers"."user_id" = $1 LIMIT $2 [["user_id", 1], ["LIMIT", 1]]
|
132
|
+
|
133
|
+
UserImage Load (11.0ms) SELECT "user_images".* FROM "user_images" WHERE "user_images"."user_id" = $1 LIMIT $2 [["user_id", 1], ["LIMIT", 1]]
|
134
|
+
|
135
|
+
Rendering text template
|
136
|
+
|
137
|
+
Rendered text template (0.0ms)
|
138
|
+
|
139
|
+
Sent data (1.0ms)
|
140
|
+
|
141
|
+
Completed 200 OK in 24ms (Views: 0.8ms | ActiveRecord: 12.4ms)
|
142
|
+
|
143
|
+
```
|