我有一個按鈕,它總是出現在html中,但默認情況下隱藏着css #comments_button{ display: none; }
。如何在Rails html.erb文件中的ruby if/else循環中執行一些jQuery?
如果通知有任何意見,我希望按鈕出現。在_notice.html.erb:
<%= button_tag "Comments", id: "comments_button" do %>
<span>Comments</span>
<% end %>
<% if notice.comments.any? %>
*** get jQuery to do $("#comments_button").show(); ***
<% end %>
如何從ruby if/else循環內部調用jQuery?
請注意,按鈕應始終存在於HTML,所以我不能做到這一點:
<% if notice.comments.any? %>
<%= button_tag "Comments", id: "comments_button" do %>
<span>Comments</span>
<% end %>
<% end %>