我得到的错误是“未定义不是函数”。我认为问题出在 app.local 部分,app.js 大约有 10 行。我是新手,正在学习教程并尝试将翡翠转换为 ejs。我有 ejs 和 express-helpers。我有一些问题已经解决,因为东西贬值了。问题在于link_to。任何想法或任何人都会遇到类似的问题这是我的 app.js
var express = require('express');
var helpers = require('express-helpers');
var ArticleProvider = require('./articleprovider-memory').ArticleProvider;
var app = module.exports = express();
app.configure(function(){
app.locals({
link_to : helpers.link_to
});
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
var articleProvider= new ArticleProvider();
app.get('/', function(req, res){
articleProvider.findAll( function(error,docs){
res.render('index.ejs', {
title: 'Blog',
articles:docs
});
});
});
和我的 index.ejs
<html>
<body>
<h1> <%= title %> </h1>
<% for (var i = 0; i < articles.length; i++) {
var article = articles[i]; %>
<%= created_at = article.created_at %> <br>
<%= link_to(title, 'blog/'+article._id) %> <br>
<%= article.body %>
<% } %>
</body>
</html>