Giter VIP home page Giter VIP logo

Comments (11)

gazay avatar gazay commented on July 30, 2024

Hey! Thanks for response!

Did you try this on new application or just on your app? What logic in your root action?

from gon.

dmonopoly avatar dmonopoly commented on July 30, 2024

In my app, I actually never go to the root action / "home" page, since the app is meant to run in Qt webkit, and the Qt application makes URL requests to the Rails app like "http://localhost:3000/[email protected]&password=admin" and then the Rails app would typically respond with the proper webpage.

I didn't try on a new application, just on this app.

The error occurs in the webpage when I test the url and in the Qt app. (If it doesn't work in the webpage, then it definitely won't work in the Qt app - I just want to point out the error doesn't have anything to do with Qt)

from gon.

gazay avatar gazay commented on July 30, 2024

I'm sorry but I can't reproduce this bug on new rails app, and don't know your environment. If you can do some debug or tests - it will be helpful! And of course it will be super if you can do pull request with tests for this case or fix for this bug :)

from gon.

dmonopoly avatar dmonopoly commented on July 30, 2024

Ah, I found out the issue: I was declaring Gon.global variables in ApplicationController where there was a before_filter:

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate!

  # These are constant variables for clear comparison/code readability across controllers and coffee files.
  # So, when a controller action uses Gon to set a variable, the coffeescript can get the same value reliably.
  # These are enums, essentially
  # these should be what controller sets gon.view to
  Gon.global.OTHER_VIEW = 'other'
  Gon.global.PROJECTS_SHOW = 'projects/show'
  Gon.global.FOLDERS_SHOW = 'folders/show'

What would be the proper place to define these global gon variables?

from gon.

gazay avatar gazay commented on July 30, 2024

I advice to create some initializer for gon and create global variables there if it's possible (if there no dynamic variables). If not - you should do some singleton method which should check define of global variables and place it before call.

from gon.

dmonopoly avatar dmonopoly commented on July 30, 2024

Okay, since the variables are static, I should simply put them in config/initializers/mygonfile.rb ? Will it be automatically included?
Thanks!

from gon.

gazay avatar gazay commented on July 30, 2024

Yes, it should) If all will be ok - please close the issue)

from gon.

dmonopoly avatar dmonopoly commented on July 30, 2024

Actually the error has to do with setting Gon.global.myvariable anywhere, it seems... when I have it set in an initializer, the error persists. I'm digging around in your code right now, and it all starts here:

gon / lib / gon / helpers.rb

  def include_gon(options = {})
    if variables_for_request_present?
      Gon::Base.render_data(options)
    elsif Gon.global.all_variables.present?
      Gon.clear
      Gon::Base.render_data(options)
    elsif options[:init].present?
      Gon.clear if Gon.all_variables.present?
      Gon::Base.render_data(options)
    else
      ""
    end
  end

The problem might stem from a misunderstanding of your include_gon method... mine has no arguments, yet Gon.clear is still being called (I suspect b/c I set global variables?)

from gon.

dmonopoly avatar dmonopoly commented on July 30, 2024

Could you clarify your usage section? https://github.com/gazay/gon#usage
I don't understand namespace or init or camel case...

from gon.

gazay avatar gazay commented on July 30, 2024

I found bug I think, I'll do new version tomorrow

Thanks!

About usage sections - I thought there are all simple - you pass some option to include gon and it's change you end javascript

from gon.

gazay avatar gazay commented on July 30, 2024

fixed in 3.0.4

from gon.

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.