前提・実現したいこと
今railsにて、あるサービスを開発してます。
そのサービスの中にいいね機能を実装しようと考えているのですが、
なかなかおもいどおりに反映されません。
どなたかご教示いただけると幸いです。
現在の課題
jsがうまくrails側のビューには反映されない
Font Awesomeが反映されない
該当のソースコード
ruby
1class LikesController < Web::BaseController 2 before_action :authenticate_user!, only: [:create, :destroy] 3 def create 4 @video = Video.find(params[:video_id]) 5 @video.favorite(current_user) 6 end 7 8 def destroy 9 @video = Video.find_by(params[:video_id]) 10 @video.unfavorite(current_user) 11 end 12 endト
Ruby
1<%= render partial: 'web/videos/partials/like', locals: {video: video} %>
ruby
1<% if user_signed_in? %> 2 <% if video.favorite?(current_user) %> 3 <%= button_to video_like_path(video, user_id: current_user.id), method: :delete, id: "like-button", remote: true do %> 4 <%= image_tag("heart-regular.svg") %> 5 <% end %> 6 <% else %> 7 <%= button_to video_likes_path(video, user_id: current_user.id, video_id: video.id), method: :post, id: "like-button", remote: true do%> 8 <%= image_tag("heart-solid.svg") %> 9 <% end %> 10 <% end %> 11<% else %> 12 <%= link_to %> 13<% end %>
Javascript
1$("#like-button").html("<%= j(render partial: 'web/videos/partials/like', locals: { video: video, likes: @likes, like: @like}) %>") 2
Javascript
1$("#like-button").html("<%= j(render partial: 'web/videos/partials/like', locals: { video: video, likes: @likes }) %>"); 2
試したこと
ローカル変数の修正やimage_tagの記述の仕方などいろいろ試しましたが反映されませんでした。
あなたの回答
tips
プレビュー