いいね機能を実装する際に、html.erb内でjavascriptを直接書いて、icon_heart.svgが押されたら画像を隠して、icon_red_heart.svgを表示させるという動きをさせたいです。どのように書けば動くでしょうか?
#_likes.html.erb <% if user_signed_in? %> <% if post.like_user(current_user.id) %> <%= button_to post_like_path(post, like), method: :delete, id: i, remote: true do %> <%= image_tag("icon_red_heart.svg") %> <span> <%= post.likes_count %> </span> <% end %> <% else %> <%= button_to post_likes_path(post.id), id: "like-button", remote: true do %> <%= image_tag("icon_heart.svg") %> <span> <%= post.likes_count %> </span> <% end %> <% end %> <% else %> <%= image_tag("icon_heart.svg") %> <span> <%= post.likes_count %> </span> <% end %> <script> window.addEventListener("load", function(){ $('#i').on("click", function(){ $('this').hide(); }) }) </script>

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/25 10:45