Created
July 3, 2011 12:36
-
-
Save pilt/1062202 to your computer and use it in GitHub Desktop.
Getting "Uncaught TypeError: Object #<Object> has no method 'products'"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The browser client. | |
now = window.now | |
Page = Backbone.Model.extend {} | |
Pages = Backbone.Collection.extend | |
mode: Page | |
window.pages = new Pages | |
Sidebar = Backbone.Model.extend { | |
loadPage: (page) -> | |
@set page: page | |
} | |
Product = Backbone.Model.extend {} | |
Products = Backbone.Collection.extend | |
mode: Product | |
window.products = new Products | |
Workspace = Backbone.Router.extend | |
routes: | |
"products": "products", | |
"product/:id": "product" | |
products: () -> | |
"moo" | |
product: (id) -> | |
"moo" | |
window.workspace = new Workspace() | |
Backbone.sync = (method, model, opts) -> | |
console.log method, model. opts | |
Backbone.history.start pushState: true | |
now.ready -> | |
console.log "now is ready" | |
now.products (prods) -> | |
products.add(prods) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nowjs = require "now" | |
express = require "express" | |
path = require "path" | |
products = require './products' | |
settings = require './config/settings' | |
app = express.createServer() | |
app.register '.coffee', require('coffeekup') | |
app.set 'view engine', 'coffee' | |
app.use express.logger() | |
app.use express.bodyParser() | |
app.configure 'development', () -> | |
projDir = path.join __dirname, '..' | |
staticDir = path.join(projDir, 'static') | |
viewsDir = path.join(projDir, 'views') | |
app.set 'views', viewsDir | |
app.use(express.static(staticDir)) | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })) | |
console.log "configured for development" | |
everyone = nowjs.initialize(app) | |
everyone.now.products = (cb) -> | |
products.all cb | |
home = (req, res) -> | |
res.render 'home' | |
app.get '/', home | |
paid = (req, res) -> | |
res.render 'paid' | |
app.get '/paid', paid | |
addProduct = (req, res) -> | |
res.render 'addProduct' | |
app.get '/products/add', addProduct | |
addedProduct = (req, res) -> | |
products.add req.body.name, req.body.price | |
listProducts req, res | |
app.post '/products/added', addedProduct | |
listProducts = (req, res) -> | |
products.all (prods) -> | |
res.render 'listProducts', locals: {products: prods} | |
app.get '/products/list', listProducts | |
app.listen(settings.nodePort) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding
--bare
(no top-level function wrapper) tocoffee
command solves it.