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

  • Home
  • SEARCH
  • 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 8475315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:51:35+00:00 2026-06-10T17:51:35+00:00

this.id is undefined in Blog.Collections.Posts class. What’s wrong? Blog collection Blog.Collections.Posts = Backbone.Collection.extend({ model:

  • 0

this.id is undefined in Blog.Collections.Posts class. What’s wrong?

Blog collection

Blog.Collections.Posts = Backbone.Collection.extend({

  model: Blog.Models.Post,
  url: function() {
    console.log(this.id);
    if (this.id) {
      return '/api/posts/'+this.id
    }
    else{
      return '/api/posts'
    }
  }

});

My router:

Blog.Routers.Posts = Backbone.Router.extend({

    routes: {
    ""                  :        "index",
    "entry/:id" :        "show"
  },

  show: function(id) {
    var collection = new Blog.Collections.Posts({id: id});
    collection.fetch({
      success: function() {
        var view = new Blog.Views.PostsIndex({ collection: collection });
        console.log(collection);
      }
    });
  }

});
  • 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-10T17:51:37+00:00Added an answer on June 10, 2026 at 5:51 pm

    Collections don’t have an id by default. Unless you’re explicitly assigning an id to your collection, this.id becomes undefined. IDs are standard attribute of models. What you want to do is simply:

    // Collection URL
    url: function() {
        return '/api/posts'
    }
    

    Backbone models, if they are a part of a collection will use the collection url when fetching and saving. Thus, if you do something like this:

    // myModel is a part of the collection
    myModel.save();
    

    It will automatically goto:

    '/api/posts/:id'  // Assuming your model already has a model.id
    

    Hope this helps.

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

Sidebar

Related Questions

I got this error: undefined method `test_path' for #<#<Class:0x4022a00>:0x4028ee0> I made this link: <%=
I am getting this error 'Cufon' is undefined on my blog http://microreviews.org The error
I have a form partial current setup like this to make new blog posts
I was reading this blog post and i was not able to understand a
I have this code: <%= @r2_blog_posts = Refinery::Blog::Post.recent(2) %> <%= link_to(@r2_blog_posts.first) do %> <%=
I'm looping my object data but am getting this undefined value. Not sure why
I'm getting this error : undefined method `has_many' for #<Formtastic::SemanticFormBuilder:0xb410d4c> It work when I
I cannot understand why this throws undefined reference to `floor' : double curr_time =
I have odd problem: After starting server I got this error: undefined local variable
Regarding the object below I am getting a 'this' is undefined error. This only

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.