質問編集履歴

3

if文変更

2018/06/19 04:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -50,18 +50,14 @@
50
50
 
51
51
  User/indexで下記のように記載すると
52
52
 
53
- undefined method `orders' for nil:NilClass
54
-
55
- となってしまいます。
53
+ 該当するデータがあるのに表示されない状態となってしまいます。
56
54
 
57
55
 
58
56
 
59
- - @users.each do |user|
57
+ - user.user_profile.present? && user.user_profile.orders.present?
60
58
 
61
- - if user.user_profile.orders.present?
59
+ - user.user_profile.orders.each do |orders|
62
60
 
63
- - user.user_profile.orders.each do |order|
64
-
65
- = order.total_price
61
+ = orders.email
66
62
 
67
63
  ```

2

if文の追加

2018/06/19 04:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  User/indexで下記のように記載すると
52
52
 
53
- undefined method `total_price' for #<ActiveRecord::Associations::CollectionProxy []>
53
+ undefined method `orders' for nil:NilClass
54
54
 
55
55
  となってしまいます。
56
56
 
@@ -58,6 +58,10 @@
58
58
 
59
59
  - @users.each do |user|
60
60
 
61
+ - if user.user_profile.orders.present?
62
+
61
- = user.user_profile.orders.total_price
63
+ - user.user_profile.orders.each do |order|
64
+
65
+ = order.total_price
62
66
 
63
67
  ```

1

typoの修正

2018/06/19 01:45

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Railsでemailマッチするデータをviewsで表示したい
1
+ Railsでemailマッチするデータをviewsで表示したい
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- User_profiles
19
+ User_profile
20
20
 
21
21
  belongs_to : user
22
22