質問編集履歴
1
コードを見やすく表示しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
プログラミング初心者です。Ruby on railsで投稿に対するいいね機能を実装したいと思い、Qiitaの
|
4
4
|
|
5
|
-
railsとjsを使ったお手軽「いいね♡機能」を参考にさせていただいたのですが、画面を
|
5
|
+
railsとjsを使ったお手軽「いいね♡機能」を参考にさせていただいたのですが、画面を更新しないとお気に入りの数が増減しません。更新をせずともそのままの画面で表示を切り替えたいのですが、方法がわかりませんので質問させていただきます。よろしくお願いいたします。
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -12,34 +12,38 @@
|
|
12
12
|
|
13
13
|
エラーメッセージ
|
14
14
|
|
15
|
+
```Ruby
|
16
|
+
|
17
|
+
ActionController::UrlGenerationError in Favorites#create
|
18
|
+
|
19
|
+
|
20
|
+
|
15
|
-
|
21
|
+
Showing /Users/lcls/newpro/leapernew/app/views/favorites/_favorite.html.erb where line #3 raised:
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
|
19
|
-
|
23
|
+
No route matches {:action=>"destroy", :building_id=>7, :controller=>"favorites", :id=>nil} missing required keys: [:id]
|
20
|
-
|
21
|
-
|
24
|
+
|
22
|
-
|
23
|
-
2: <% if @building.favorite_user(current_user.id) %>
|
24
|
-
|
25
|
-
3: <%= button_to building_favorite_path(@favorites, building_id: @building.id), method: :delete, id: "favorite-of-#{@building.id}", remote: true do %>
|
26
|
-
|
27
|
-
|
25
|
+
Trace of template inclusion: app/views/favorites/create.js.erb
|
28
|
-
|
29
|
-
|
26
|
+
|
30
|
-
|
31
|
-
|
27
|
+
Rails.root: /Users/lcls/newpro/leapernew
|
28
|
+
|
29
|
+
|
30
|
+
|
32
|
-
|
31
|
+
Application Trace
|
32
|
+
|
33
|
-
|
33
|
+
app/views/favorites/_favorite.html.erb:3:in `_app_views_favorites__favorite_html_erb__4167235874778328999_70128592674580'
|
34
|
-
|
34
|
+
|
35
|
-
|
35
|
+
app/views/favorites/create.js.erb:1:in `_app_views_favorites_create_js_erb__4231897082744261259_70128595192160'
|
36
|
+
|
36
|
-
|
37
|
+
```
|
37
|
-
|
38
38
|
|
39
39
|
###該当のソースコード
|
40
40
|
|
41
|
+
```Ruby
|
42
|
+
|
41
43
|
**buildings.controller.html.erb**
|
42
44
|
|
45
|
+
|
46
|
+
|
43
47
|
class BuildingsController < ApplicationController
|
44
48
|
|
45
49
|
|
@@ -64,10 +68,14 @@
|
|
64
68
|
|
65
69
|
end
|
66
70
|
|
67
|
-
|
71
|
+
```
|
72
|
+
|
73
|
+
```Ruby
|
68
74
|
|
69
75
|
**favorites.controller.html.erb**
|
70
76
|
|
77
|
+
|
78
|
+
|
71
79
|
class FavoritesController < ApplicationController
|
72
80
|
|
73
81
|
|
@@ -108,22 +116,30 @@
|
|
108
116
|
|
109
117
|
end
|
110
118
|
|
111
|
-
|
119
|
+
```
|
120
|
+
|
121
|
+
```Ruby
|
112
122
|
|
113
123
|
**views/buildings/show.html.erb**
|
114
124
|
|
125
|
+
|
126
|
+
|
115
127
|
<div class="button_wrapper">
|
116
128
|
|
117
129
|
<button class="button button1"><i class="fa fa-paper-plane-o fa-fw fa-lg" aria-hidden="true"></i>お問い合わせする</button>
|
118
130
|
|
119
131
|
<%= render partial: 'buildings/buildings', locals: { building: @building, favorites: @favorites, favorite: @favorite } %>
|
120
132
|
|
121
|
-
|
133
|
+
</div>
|
134
|
+
|
122
|
-
|
135
|
+
```
|
136
|
+
|
123
|
-
|
137
|
+
```Ruby
|
124
138
|
|
125
139
|
**views/buildings/_buildings.html.erb**
|
126
140
|
|
141
|
+
|
142
|
+
|
127
143
|
<span id="favorite-of-<%= @building.id %>">
|
128
144
|
|
129
145
|
<%= render partial: 'favorites/favorite', locals: { building: @building, favorites: @favorites, favorite: @favorite } %>
|
@@ -132,8 +148,14 @@
|
|
132
148
|
|
133
149
|
|
134
150
|
|
151
|
+
```
|
152
|
+
|
153
|
+
```Ruby
|
154
|
+
|
135
155
|
**views/favorites/_favorite.html.erb**
|
136
156
|
|
157
|
+
|
158
|
+
|
137
159
|
<% if user_signed_in? %>
|
138
160
|
|
139
161
|
<% if @building.favorite_user(current_user.id) %>
|
@@ -184,19 +206,41 @@
|
|
184
206
|
|
185
207
|
|
186
208
|
|
209
|
+
```
|
210
|
+
|
211
|
+
```Javascript
|
212
|
+
|
187
213
|
**create.js.erb**
|
188
214
|
|
215
|
+
|
216
|
+
|
189
217
|
$("#favorite-of-<%= @building.id %>").html("<%= j(render partial: 'favorite', locals: { building: @building, favorites: @favorites, favorite: @favorite }) %>");
|
190
218
|
|
191
|
-
|
219
|
+
```
|
220
|
+
|
221
|
+
```Javascript
|
192
222
|
|
193
223
|
**destroy.js.erb**
|
194
224
|
|
225
|
+
|
226
|
+
|
195
227
|
$("#favorite-of-<%= @building.id %>").html("<%= j(render partial: 'favorite', locals: { building: @building, favorites: @favorites, favorite: @favorite }) %>");
|
196
228
|
|
229
|
+
```
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
197
241
|
###試したこと
|
198
242
|
|
199
|
-
local変数の受け渡しがうまくいってないと予想して何度か書き直してみましたが、再
|
243
|
+
local変数の受け渡しがうまくいってないと予想して何度か書き直してみましたが、再読み込みなしではお気に入りボタンの表示が切り替わりませんでした。
|
200
244
|
|
201
245
|
|
202
246
|
|