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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:38:49+00:00 2026-06-15T18:38:49+00:00

I am new to Backbone + Coffeescript + Rails and I’m stuck in initializing

  • 0

I am new to Backbone + Coffeescript + Rails and I’m stuck in initializing the application. The main_app.js.coffee is:

#= require_self
#= require_tree ./templates
#= require_tree ./models
#= require_tree ./views
#= require_tree ./routers

class window.BackofficeApp
  Models: {}
  Collections: {}
  Routers: {}
  Views: {}

  sanity:-> true

  constructor: ->
        console.log "go backofficeapp!"
        new BackofficeApp.Router()
        try
            Backbone.history.start()

The router is still pretty simple:

class BackofficeApp.Router extends Backbone.Router

    routes:
        "": "index",
        "users": "users",
        "csense": "csense"

    index: ->
        console.log "index called from router!"
        view = new BackofficeApp.Views.IndexView()
        $('#main-app').html(view.render().el)

    users: ->
        console.log "users"

    csense: ->
        console.log "contentsense!"

And the IndexView as well:

class BackofficeApp.Views.IndexView extends Backbone.View    

    render: ->
        template = JST['index_view']
        $(@el).html(template);
        console.log "index called from indexview!"
        this

Everything starts in jQuery (doc ready):

jQuery ->
    new BackofficeApp()

But we are seeing the following msgs / error in the console:

Uncaught TypeError: Cannot read property 'IndexView' of undefined
go backofficeapp!
index from router! 

If I take the .Views out of IndexView class declaration, it works… However, as the app is medium to large, we would like to use 2 (or more) levels in naming the classes.

What are we doing wrong?

  • 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-15T18:38:50+00:00Added an answer on June 15, 2026 at 6:38 pm

    This doesn’t do what you think it does:

    class window.BackofficeApp
      Models: {}
      Collections: {}
      Routers: {}
      Views: {}
    

    That will create window.BackofficeApp but Models, Collections, … will be attached to BackofficeApp.prototype rather than BackofficeApp itself. The JavaScript version is like this:

    window.BackofficeApp = (function() {
      function BackofficeApp() {}
      BackofficeApp.prototype.Models = {};
      BackofficeApp.prototype.Collections = {};
      BackofficeApp.prototype.Routers = {};
      BackofficeApp.prototype.Views = {};
      return BackofficeApp;
    })();
    

    I think you want to make Models and friends class properties:

    class window.BackofficeApp
      @Models: {}
      @Collections: {}
      @Routers: {}
      @Views: {}
    

    That will create BackofficeApp.Models, BackofficeApp.Collections, … so that you can say:

    class BackofficeApp.Views.IndexView extends Backbone.View
      #...
    

    without seeing TypeErrors.

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

Sidebar

Related Questions

I have this code in Coffeescript window.App = new Backbone.Marionette.Application Models: {} Collections: {}
I am new to backbone and I am stuck with a problem problem in
I'm pretty new to Backbone.js and Require.js. In my app I'm loading templates into
Im using backbone, require.js and coffeescript in a application. Programming my app, discovered i
Rails app, learning CoffeeScript and Backbone.js: Uncaught TypeError: Cannot use 'in' operator to search
I have the following Backbone router definition in CoffeeScript: // appointments_router.js.coffee define [app, appointment],
I am building a backbone.js app on a Rails 3.1 back-end. I'm using CoffeeScript
I'm writing specs for some Javascript classes (backbone.js views, written in Coffeescript) and I'd
I'm new to the world of coffeescript (javascript). Currently building my first backbone.js app
Backbone.js documentation suggest loading bootstrapped models this way: <script> var Accounts = new Backbone.Collection;

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.