teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コードの修正

2020/08/17 00:47

投稿

tmrk77
tmrk77

スコア1

title CHANGED
File without changes
body CHANGED
@@ -29,11 +29,26 @@
29
29
  end
30
30
 
31
31
  def show
32
+ @products = Product.all
33
+ if @product == @products.first
34
+ @next_product = Product.next_search(@product)
35
+ elsif @product == @products.last
36
+ @prev_product = Product.prev_search(@product)
37
+ else
38
+ @prev_product = Product.prev_search(@product)
39
+ @next_product = Product.next_search(@product)
32
- 中略
40
+ end
41
+ @grandchild = Category.find(@product.category_id)
42
+ @child = @grandchild.parent
43
+ @parent = @child.parent
44
+ @parent_category_products = @products.select { |product| product.category.root.name == @parent.name }
45
+ @user = current_user
46
+ Payjp.api_key = ENV['PAYJP_PRIVATE_KEY']
47
+ @card = CreditCard.find_by(user_id: current_user)
33
- if user_signed_in?
48
+ if user_signed_in?
34
49
  @favorite = Favorite.find_by(user_id: current_user.id, product_id: params[:id])
50
+ end
35
51
  end
36
- end
37
52
  ```
38
53
  ```favorites
39
54
  class FavoritesController < ApplicationController
@@ -95,20 +110,20 @@
95
110
  favorites/_favorite.html.haml
96
111
  ```
97
112
  - if user_signed_in?
98
- - if current_user.already_favorited?(@product)
113
+ - if current_user.already_favorited?(product)
99
- = link_to product_favorite_path(@product, @favorite), method: :delete, remote: true do
114
+ = link_to product_favorite_path(product, @favorite), method: :delete, remote: true do
100
115
  %i.fas.fa-star
101
116
  お気に入り
102
- = @product.favorites.count
117
+ = product.favorites.count
103
118
  - else
104
- = link_to product_favorites_path(@product), method: :post, remote: true do
119
+ = link_to product_favorites_path(product), method: :post, remote: true do
105
120
  %i.far.fa-star
106
121
  お気に入り
107
- = @product.favorites.count
122
+ = product.favorites.count
108
123
  - else
109
124
  = icon('fa', 'star')
110
125
  お気に入り
111
- = @product.favorites.count
126
+ = product.favorites.count
112
127
  ```
113
128
  favorites/_products_favorite.html.haml
114
129
  ```

1

実装機能のタイトルの追加

2020/08/17 00:47

投稿

tmrk77
tmrk77

スコア1

title CHANGED
@@ -1,1 +1,1 @@
1
- NoMethodError undefined method `id' for nil:NilClass
1
+ いいね機能 NoMethodError undefined method `id' for nil:NilClass
body CHANGED
File without changes