I'm having trouble with a Bootstrap popover inside my navbar. The navbar is in the main application.html.erb. It works once the page is loaded, but once I move onto another page, the popover stops working until the site is refreshed again. Here's the html/ruby:
<button class = "btn navbar-btn btn-primary" id="popoverFriends" data-placement = "bottom" data-trigger="focus">Workplace Proximity Acquaintances <span class="badge"><%= @user.pending_friends.count %></span></button>
<div id="popoverFriendsHiddenContent" style="display: none">
<% unless @user.pending_friends.empty? %>
<% @user.pending_friends.each do |u| %>
<h3 class="text-center"><%= link_to u.username, user_path(u.id) %>
<%= link_to 'YAY!', user_friend_path(:user_id => current_user, :friend_id => u), class: "btn btn-warning", :method => :put, :confirm => 'Accept friend request! Are you sure?' %>
<%= link_to 'No.', user_friend_path(:user_id => current_user, :friend_id => u), class: "btn btn-danger", :method => :delete, :confirm => 'Reject friend request! Are you sure?' %>
<% end %>
<% else %>
None :(
<% end %>
</h3>
</div>
<div id="popoverFriendsHiddenTitle" style="display: none">
<h3>Your requests: </h3>
</div>
</div>
And the .js
$(document).ready(main)
var main = function(){
$('[data-toggle="popover"]').popover()
$("#popoverFriends").popover({
html : true,
content: function() {
return $('#popoverFriendsHiddenContent').html();
},
title: function() {
return $('#popoverFriendsHiddenTitle').html();
}
});
};
Please let me know if I'm missing something so that the popover stays persistent through the site.