前提・実現したいこと
Ajaxを使っていいね機能を実装したい(Ruby on Rails)
発生している問題・エラーメッセージ
コードが入り組んでいて、どこに<div id=" ">をセットすればいいのか分からない。
jsで書き替えたいのは、いいねのアイコンといいねカウントです。
該当のソースコード
_micropost.html.erb
Ruby
1<% if Like.find_by("micropost_id = #{micropost.id} AND user_id = #{@current_user.id}") %> 2 <%= link_to("/likes/#{micropost.id}/destroy", method: :post) do %> 3 <i class="fas fa-star fa-fw star"></i> 4 <% end %> 5<% else %> 6 <%= link_to("/likes/#{micropost.id}/create", {method: 'post'}) do %> 7 <i class="fas fa-star fa-fw unstar"></i> 8 <% end %> 9<% end %> 10<%= Like.where(micropost_id: micropost.id).count %>
もう少し前後関係が欲しいです!
数値を表示するフィールドはどこに置く予定でしょうか?
回答1件
あなたの回答
tips
プレビュー