回答編集履歴
1
追記
answer
CHANGED
@@ -1,2 +1,17 @@
|
|
1
1
|
session[:card_id] が残っている? というのは不思議ですが、その前にuserとcartの関係定義ができていないのでは? と思われます。
|
2
|
-
User と Cart の関係定義のところを見せて下さい。 has_* とか belongs_toとかのところです
|
2
|
+
User と Cart の関係定義のところを見せて下さい。 has_* とか belongs_toとかのところです
|
3
|
+
###
|
4
|
+
関連定義を追加しましょう
|
5
|
+
|
6
|
+
class User に has_one :cart
|
7
|
+
class Cart に belongs_to :user
|
8
|
+
|
9
|
+
Userのcontroller の create で,成功した後で
|
10
|
+
成功したuser.cart.create としておきましょう
|
11
|
+
|
12
|
+
そうすると、user.cart でcartが得られますのでsessionに取っておく必要がなくなります。
|
13
|
+
|
14
|
+
あと、Cart,Productとの関係では
|
15
|
+
cartに has_many :products, through :cart_items
|
16
|
+
productに has_many :carts, through :cart_items
|
17
|
+
も定義しておくほうが良いかと。
|