0

Currently working on a project on my local machine to learn RoR. When I navigate to localhost:3000, the page looks great. The masonry animations work just fine.

However, if at any point I click my navbar-brand to go back to localhost:3000, the masonry does not work. However, if I refresh the page, the masonry returns.

I tried a few different things, but each has been giving me other errors..

Here is how my html, head, and body in application.html.haml are set up (the right way, I think):

!!! 5
%html
    %head
        %title My App
        = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true 
        = javascript_include_tag 'application', 'data-turbolinks-eval' => true 
        = csrf_meta_tags
        %body
            %nav.navbar.navbar-default
                .container
                    .navbar-brand= link_to "My App", root_path

If I purposefully set the %head indentation back so it is just under %head:

!!! 5
%html
%head
    %title My App
    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true 
    = javascript_include_tag 'application', 'data-turbolinks-eval' => true 
    = csrf_meta_tags
    %body
        %nav.navbar.navbar-default
            .container
                .navbar-brand= link_to "My App", root_path

then the issue where masonry does not apply on redirect back to index is gone. However, another issue then presents itself. I have a confirm for my delete, so with this setup the confirm box does not go away even after I click OK. That happens in my show.html.haml here:

= link_to "Remove", shape_path, method: :delete, 
  data: { confirm: "Click OK to remove" }

I am really lost and would appreciate some help. Thank you.

chintoo
  • 27
  • 6

1 Answers1

1

I had the same problem. When you click in a navbar link the page is not reloaded. I solve this problem using the gem jquery-turbolink

add to your Gemfile:

gem 'jquery-turbolinks'

then run in your terminal

bundle install

and add this to your application.js

//= require jquery.turbolinks

I found the solution here:

JQuery gets loaded only on page refresh in Rails 4 application

Community
  • 1
  • 1
Well
  • 11
  • 2