Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:26:23+00:00 2026-06-01T15:26:23+00:00

I have a Rails 3.2.3 app with Backbone.js and I’m using pushState on my

  • 0

I have a Rails 3.2.3 app with Backbone.js and I’m using pushState on my Backbone.history.

The Problem

When I click on a link which goes to say ‘/foo’ to show appointment with ID: 1, then Backbone router gets to that first, which I can quickly see before Rails router takes over and complains that there is no route for /foo.

My Backbone.js code

Here is my backbone router.

window.AppointmentApp = new (Backbone.Router.extend({
    routes: {
        "": "index",
        "foo": "foo",
        "appointments": "index",
        "appointments/:id": "show"
    },
    foo: function(){
        $("#app").append("foo<br />");
    },
    initialize: function() {
        this.appointments = new Appointments();
        this.appointmentListView = new AppointmentListView({ collection: this.appointments });
        this.appointmentListView.render();
    },
    start: function() {
        Backbone.history.start({pushState: true});
    },
    index: function() {
        $("#app").html(this.appointmentListView.el);
        this.appointments.fetch();
    },
    show: function(id) {
        console.log("Enter show");
    }   
}));

It should stay on the same page and attach a ‘foo’ to the end of the #app div, but it never does.

Backbone index viewer

window.AppointmentListView = Backbone.View.extend({
    template: JST["appointments/index"],
    events: {
        "click .foo": function(){Backbone.history.navigate("foo");},
    },
    comparator: function(appointment){
        return appointment.get('topic');
    },
    initialize: function(){
        this.collection.on('reset', this.addAll, this);
    },
    render: function(){
        this.$el.html(this.template);
        this.addAll();
        return this;
    },
    addAll: function() {
        this.collection.forEach(this.addOne, this);
    },
    addOne: function(appointment){
        var appointmentView = new AppointmentView({model: appointment});
        this.$el.append(appointmentView.render().el);
    }
});

app/assets/templates/appointments/Index.jst.ejs

<h1>Appointments</h1>
<a href="/foo" class="foo">Say Foo</a>
<a href=appointments/add>Add</a>
<div id="app"></div>

I was using pushState as it allows me to keep a history and the Back button functionality.

The Backbone.history.navigate doesn’t call my Backbone route, it calls the Rails route instead. How do I go about fixing this?

Should I be trying to setup Backbone to accept routes such as ‘appointments/1’ and taking control or do I have to use a click event with a Backbone.history.navigate call like above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:26:24+00:00Added an answer on June 1, 2026 at 3:26 pm

    You need to return false from your click .foo event handler, otherwise the browser will continue as if you’d clicked the link normally and request the actual /foo page from the server.

    I think you’ve also got the call to Backbone.history.navigate("foo"); wrong – Backbone.history doesn’t have a navigate function as far as I can see from the documentation. You should actually be calling .navigate on your Backbone.Router instance, and passing in the trigger option to cause it to call trigger the route. For example:

    window.AppointmentApp.navigate("foo", { trigger : true } );
    

    You may already know this but if you’re planning on using pushState then you should really update your server side to support all the URLs that your client side does. Otherwise if a user decides to copy & paste the URL into another tab, they will just run into rails complaining that there is no route.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I have rails app which are working perfectly in the local computer. But when
I have rails app which has a list of users. I have different relations
I have a Rails 3.1 app that uses the codebrew/backbone-rails . In a .jst.ejs
I have a rails app that is combining javascript assets using Jammit , and
I'm currently trying Backbone.js along with a rails app. My problem is, that I
I have a rails app which uses omniauth to authenticate visitors via facebook. When
I have notifications in my Rails & Backbone.js app // MODEL NotificationModel = App.BB.Model.extend({
I'm using Backbone with Rails (3.1). I have a search page. The first search
I have a Rails app using AuthLogic and have gotten it to the point

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.