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 8963699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:24:55+00:00 2026-06-15T16:24:55+00:00

I am new to Backbone and I’m having problem saving a model to database.

  • 0

I am new to Backbone and I’m having problem saving a model to database. When clicking, the field ‘profile’ should be updated to ‘100’, but it is not working:

$ ->

class User extends Backbone.Model
    url: -> '/users/' + this.get("id")  '.json'

class Users extends Backbone.Collection
    model: User

class UserView extends Backbone.View
    tagName: "li"
    events:
        "click" : "changeProfile"

    render: -> $(@el).html( @model.get "name" )
    changeProfile: -> 
        $('li').removeClass('selected')
        $(@el).addClass('selected')
        @model.set( 'profile' : '100' ).save()

users = new Users
users.url = "/users.json"
users.fetch(
    success: ->
        _.each users.models, (model) ->
            view = new UserView( model: model )
            $('ul').append view.render()
)

The ‘users’ controller / ‘user’ model were scaffolded (and the controller renders in json). I am using latest versions of both Backbone and Rails. Can somebody help?

(Javascript Console in Chrome register the following error: “Uncaught TypeError: number is not a function”)

  • 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-15T16:24:56+00:00Added an answer on June 15, 2026 at 4:24 pm

    Your url for User is missing a +:

    class User extends Backbone.Model
        url: -> '/users/' + this.get("id")  '.json'
        #---------------------------------^^
    

    The last part of that is being interpreted like this:

    this.get("id")('.json')
    

    and since get('id') is returning a number, you get a “number is not a function” error. Add the missing + to get string concatenation or use CoffeeScript’s interpolation:

    url: -> '/users/' + this.get('id') + '.json'
    

    or

    url: -> "/users/#{this.get('id')}.json"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a new virtual field to my backbone model whenever a
I know how to create a new backbone model. But how I can create
I am having trouble with some really basic Backbone.js functionality. window.Album = new Backbone.Model.extend({});
Backbone.js makes a POST request when a new model is created and saved, but
I am new to backbone and I am stuck with a problem problem in
I'm pretty new to Backbone and Marionette and am having a tough time getting
I'm very new to backbone but I manage to get it working from tutorial.
I'm new to Backbone. Is it possible to define a Model in backbone which
I'm new to backbone.js and I've read other solutions to similar problems but still
I'm new to Backbone.js, and someone who comes out of the 'standard' model of

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.