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

質問編集履歴

2

題名と内容の変更

2019/12/17 03:17

投稿

hiroro0820
hiroro0820

スコア13

title CHANGED
@@ -1,1 +1,1 @@
1
- goodボタンをAjax非同期処理にしたい、うくいかない
1
+ link_to のremote:true js 読み込ない
body CHANGED
@@ -4,8 +4,12 @@
4
4
  いま、ついたアンサーにたいしてgoodかbadで評価できる機能を作っています。
5
5
 
6
6
  answerにgoodボタン、badボタンをつけるとこ
7
- までは、なんとか、できまし
7
+ までは、できたのですが
8
8
 
9
+ [railsとjsを使ったお手軽「いいね♡機能」
10
+ ](http://https://qiita.com/YuitoSato/items/94913d6a349a530b2ea2)
11
+ の記事を参考に
12
+
9
13
  そこからajaxを使って非同期処理を実装しようというときに
10
14
  下記のようなエラーが出てしまいました。
11
15
 
@@ -19,9 +23,6 @@
19
23
  読み込まれていないことが分かったのですが
20
24
  どうすればエラーが解決できるか全くわからず困っています。
21
25
 
22
- このエラーを解決するのに
23
- どうか、皆さんのお力を貸していただけると嬉しいです。
24
-
25
26
  よろしくお願いします。
26
27
 
27
28
  ### 該当のソースコード
@@ -48,9 +49,9 @@
48
49
  answer_id: params[:answer_id]
49
50
  )
50
51
  @good.destroy
51
- redirect_to("/communities/#{params[:community_id]}/ques/#{params[:que_id]}/answers/#{params[:answer_id]}/show")
52
52
  end
53
53
  end
54
+
54
55
  ```
55
56
  app/views/answers/show.html.erb
56
57
  ```ここに言語を入力
@@ -61,14 +62,14 @@
61
62
 
62
63
  <% if user_signed_in? %>
63
64
  <%#= good %>
64
- <div id="goods_buttons_<%= @answer.id %>">
65
+ <span id="good-of-<%= @answer.id %>">
65
- <%= render partial: 'goods/good', locals: { user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id} %>
66
+ <%= render partial: 'goods/good', locals: { user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id } %>
66
- </div>
67
+ </span>
67
68
 
68
69
  <%#= bad %>
69
- <div id="bads_buttons_<%= @answer.id %>">
70
+ <span id="bad-of-<%= @answer.id %>">
70
- <%= render partial: 'bads/bad', locals: { user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id} %>
71
+ <%= render partial: 'bads/bad', locals: { user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id } %>
71
- </div>
72
+ </span>
72
73
 
73
74
  <% end %>
74
75
 
@@ -89,9 +90,9 @@
89
90
  ```
90
91
  app/views/goods/create.js.erb
91
92
  ```ここに言語を入力
92
- $('#goods_buttons_<%= @answer.id %>').html("<%= j(render partial: 'goods/good', locals: {user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id}) %>");
93
+ $("#good-of-<%= @answer.id %>").html("<%= j(render partial: 'good', locals: { user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id }) %>")
93
94
  ```
94
95
  app/views/goods/destroy.js.erb
95
96
  ```ここに言語を入力
96
- $('#goods_buttons_<%= @answer.id %>').html("<%= j(render partial: 'goods/good', locals: {user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id}) %>");
97
+ $("#good-of-<%= @answer.id %>").html("<%= j(render partial: 'good', locals: { user_id: current_user.id, answer_id: @answer.id, community_id: @community.id, que_id: @que.id }) %>")
97
98
  ```

1

誤字

2019/12/17 03:17

投稿

hiroro0820
hiroro0820

スコア13

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  プログラミングを始めてまだ二か月の初心者です。
2
2
  練習がてら、railsでコミュニティ型のQ&Aサイトを作っています。
3
3
 
4
- いま、ついたアンサーにしてgoodかbadで評価できる機能を作っています。
4
+ いま、ついたアンサーにたいしてgoodかbadで評価できる機能を作っています。
5
5
 
6
6
  answerにgoodボタン、badボタンをつけるとこ
7
7
  までは、なんとか、できました!