Search code examples
jqueryruby-on-railsturbolinks

Page load on click of link, does not work


I have a side bar, in which there is a link to account page. Now on the click of the account in that sidebar, the regarding javascript is not executing, how ever if I reload the page it's executing properly. I can't understand the behaviour. Can anyone help me understand the issue

$(document).on("ready page:load",function(){

    makeProfile();

});




function makeProfile(){

        $('#profile-form').hide();

        $('.profile-edit').on("click",function(e){


            // if they click on edit, show the form, other wise show the divs
          if($('.profile-edit').text() == "Edit"){
            $('.profile-edit').text("Save");
            $('.profile-details').hide();
            $('#profile-form').show();
          }else{

                $('.submit-hidden').click();

          }

        });
}

Solution

  • try turbolinks:load

    $(document).on("turbolinks:load",function(){
    
        makeProfile();
    
    });