Source: github
In trying to pass a freshly instantiated mongoose.model through expressjs' render
function, I come upon the following error: "ReferenceError: jade is not defined"
The controller...
var mongoose = require("mongoose")
, Client = mongoose.model("Client")
exports.new = function (req, res) {
res.render("clients/new", {
headline: "New Client",
client: new Client({})
})
}
I have also tried client: new Client()
, storing the instantiated object in a var then passing it to the final render object with no change. Removing the new Client({})
bit gets past the 500 error, but does not solve the issue at hand.
Some config...
app.set("views", __dirname + "/app/views")
app.set("view engine", "jade")
The model...
var mongoose = require("mongoose")
, Schema = mongoose.Schema
var Client = new Schema({
company: { type: String },
contact: {
name: { type: String },
phone: { type: String },
email: { type: String }
},
created: { type: Date, default: Date.now }
})
mongoose.model("Client", Client)
Node v0.8.12
Express >= v3.0.0
Mongoose v3.3.1
Jade v0.27.6
Source: github
This problem is obviously caused by a keyword clash within the jade template engine.
I found your problem description interesting enough to try it out myself. After changing the jade template variable identifier client
to myclient
and passing a new mongoose Client
model instance everything worked fine:
In app/controllers/clients_controller:
...
res.render("clients/new", {
headline: "New Client",
myclient: new Client({company: 'Foo Company'})
})
...
In views/clients/new:
...
input(type='text',name='company',placeholder='Company',value='#{myclient.company}')
...
I forked your repository, committed those changes and send you a pull request (first and foremost because I'm relatively new to git and grab every chance to learn some more basics).