Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In combination with turbolinks getting error #134

Open
pbrazdil opened this issue Dec 13, 2012 · 5 comments
Open

In combination with turbolinks getting error #134

pbrazdil opened this issue Dec 13, 2012 · 5 comments

Comments

@pbrazdil
Copy link

Backbone-rails isn't compatible with Turbolinks gem, which it will has to be since turbolinks gem going to be in Rails 4.0

When I load page and then click on some link which will be processed by turbolinks, getting error below

Uncaught Error: Backbone.history has already been started

@hyperrjas
Copy link

I have the same problem +1

@hyperrjas
Copy link

I have fixed the problem. I don't know if this is correct:

initialize: ->
  new MyApp.Routers.Posts
  Backbone.history.start() unless Backbone.History.started
  $(document).on "page:change", ->
    Backbone.history.stop()
    Backbone.history.start()

Please correct me if I'm wrong. thanks

@carlosmoralesla
Copy link

I tried your code but seems not to be running.
Are you sure that "initialize: ->" code is correct?

initialize: ->
new MyApp.Routers.Posts
Backbone.history.start() unless Backbone.History.started
$(document).on "page:change", ->
Backbone.history.stop()
Backbone.history.start()

@pbrazdil
Copy link
Author

It's 3 years old
čt 25. 8. 2016 v 6:50 odesílatel Carlos Morales [email protected]
napsal:

I tried your code but seems not to be running.
Are you sure that "initialize: ->" code is correct?

initialize: ->
new MyApp.Routers.Posts
Backbone.history.start() unless Backbone.History.started
$(document).on "page:change", ->
Backbone.history.stop()
Backbone.history.start()


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#134 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABYDLfvcGnMZM4szmsTAwzIJQdrCduSoks5qjR8PgaJpZM4AUBDl
.

@DanTaiko
Copy link

DanTaiko commented Aug 26, 2017

I had the same problem.
The solution of @hyperrjas should be workable, unless turbolink is set.

With 'turbolink' I got the following possible solution that works for me (enviroment: Rails v5.1.1, jQuery v3.2.1, Backbone 1.2.0):

initialize: ->
    new MyApp.Routers.Posts
    Backbone.history.start() unless Backbone.History.started
    $(document).on "turbolinks:click", ->
      Backbone.history.stop() 

Or even more simple one, depending of your need:

initialize: ->
    new MyApp.Routers.Posts
    Backbone.history.start() unless Backbone.History.started

I don't think it's a Backbone-rails bug, it lies in understanding of the Backbone.routing and Turbolink events.

Hope it will be helpfull to someone. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants