我得到的错误是“未定义不是函数”。我认为这个问题在app.local部分中大约有10行进入app.js.我是新手,并按照教程和尝试 把玉变成ejs。我有ejs和快递助手。我有一些问题已经解决,因为东西被折旧了。问题在于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>
答案 0 :(得分:2)