【发布时间】:2021-08-20 18:00:49
【问题描述】:
我在我的 rails 应用程序(instagram-clone)的最后一步,问题是当我点击心脏标志时,喜欢的数量从 0 升级到 1,但是我找不到解决方案当我点击它时将我的徽标的背景颜色更改为“红色”,this is my logo image
这是我的投票.js.erb:
<% if current_user.liked? @post %>
$(".like-button").addClass("liked");
<% else %>
$(".like-button").removeClass("like-button");
<% end %>
$(".likes-count").html(" <%= @post.get_upvotes.size%> ")
#i want to modify this lines to change the background color of my heart logo to red when the count of likes was upgraded from 0 to 1 and thanks a lot
这是我喜欢的按钮代码行:
<%= link_to like_post_path(post), class:"like-button", method: :put, remote: :true do %>
<div>
<i class="fas fa-heart fa-2x"></i>
</div>
<% end %>
<span class="likes-count"><%= post.get_upvotes.size %></span>
【问题讨论】:
-
ruby 模板是在服务器端渲染的,对吧?
-
那个标志在哪里?请显示minimal reproducible example
-
请edit添加更多信息的问题,请参阅minimal reproducible example - 特别是我们想看看您的“标志”是如何呈现的 - 例如它只是没有透明背景的图像吗?
-
尝试:
$(".like-button i.fa-heart").css("background-color", "red")在$(".like-button").addClass("liked");行之后
标签: javascript jquery ruby erb ruby-on-rails-6