GithubHelp home page GithubHelp logo

Comments (6)

reed avatar reed commented on July 18, 2024

Gon can be used in a handful of different ways, so it's hard for me to suggest anything with confidence. How are you using it in your application?

from turbolinks-compatibility.

jondkinney avatar jondkinney commented on July 18, 2024

I set a handful of variables I want access to on every request (for some analytics libs) in a before filter in the application controller. Then in a few spots in the regular workflow of the app I set a variable here or there in a controller action directly.

The vars from the application_controller before filter come through fine because they're known at the beginning of the request and have the benefit of a full page load. The variable from say a show action of a controller giving me that object's id is what I'm running into as an issue with the suggested setup of gon.

I'm experimenting with putting the gon initialization just inside the opening body tag and loading my main javascript include tag at the bottom of the body (just before my analytics code) instead of the more traditional setup of putting the js include tag in the head and having the gon initialization as the first thing in the head (above the aforementioned js include tag). Hopefully I'm headed in the right direction, thoughts?

from turbolinks-compatibility.

reed avatar reed commented on July 18, 2024

Yeah, I think you've got the right idea. You shouldn't move your main javascript to the body, though, because it will run on every page change. Provided you're not attempting to access the gon data before DOM ready, I would think that just moving the gon initialization inside the body would be sufficient.

from turbolinks-compatibility.

geoffw8 avatar geoffw8 commented on July 18, 2024

Was there ever a proper solution to this? I'm experiencing the exact same thing at the moment

from turbolinks-compatibility.

jondkinney avatar jondkinney commented on July 18, 2024

@geoffw8 right now what is working for me is including gon as the first thing inside the body. I actually also have it in the head too (which probably isn't necessary and I'll test removing it this week).

from turbolinks-compatibility.

geoffw8 avatar geoffw8 commented on July 18, 2024

@jondkinney thanks for getting back to me. You know, I tried that but I kept getting gon is not defined so what I WILL try is having it in both the header and the body. Thats might be the trick

from turbolinks-compatibility.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.