close
 
1.css,js使用路徑
app.js
app.use('/bower_components',express.static(__dirname+'/bower_components'));
layout.jade
link(href="/bower_components/bootstrap/dist/css/bootstrap.css",rel="stylesheet")
script(src="/bower_components/bootstrap/dist/js/bootstrap.min.js")
script(src="/bower_components/bootstrap/jquery/dist/jquery.min.js")

2.mongoose 測試是否連線成功

// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {  
  console.log('Mongoose default connection open to ' + dbURI);
}); 

// If the connection throws an error
mongoose.connection.on('error',function (err) {  
  console.log('Mongoose default connection error: ' + err);
}); 

// When the connection is disconnected
mongoose.connection.on('disconnected', function () {  
  console.log('Mongoose default connection disconnected'); 
});

// If the Node process ends, close the Mongoose connection 
process.on('SIGINT', function() {  
  mongoose.connection.close(function () { 
    console.log('Mongoose default connection disconnected through app termination'); 
    process.exit(0); 
  }); 

}); 

3.res.send(err)

4.

Mongoose: Cast to ObjectId failed for value

要自己添加_id:String到schema

var MovieSchema=new mongoose.Schema({
_id:Number,
title:String,
director:String,
nation:String,
5.moment使用方式
jade
td #{moment(movie.meta.createAt).format('MM/DD/YYYY')}

app.js

app.locals.moment=require('moment');
6.jquery 取得屬性data-id方式

$(this).data('id')

7.

Can't set headers after they are sent。

不可以在處裡數據之前res.send

8.

用resteasy要用 Header Content-Type application/json

9.

findByIdAndUpdate(id,object,function(err,movie){})
10.
加上input name="_method" value="put" 讀不到 put會變get ,所以要加一個套件 method-override 

your app like this:

var methodOverride = require('method-override')
app.use(methodOverride('_method'));

Old versions might use:

app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(express.methodOverride());

An even older usage was:

app.use(express.bodyParser());
app.use(express.methodOverride());

然後

form.form-horizontal(method="post" action="/admin/movie/update/#{moviedata.id}?_method=PUT")
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 學習程式 的頭像
    學習程式

    程式學習日記,如果我幫助了你請讓我知道

    學習程式 發表在 痞客邦 留言(0) 人氣()