Geddy – 创build新项目

我是一个绝对的初学者在node.js和geddy。 我跟着几个教程,现在我试着写一些类似的东西来达到我的目的。

当我尝试创build新项目时,我收到以下消息:

/arithmetic_problem_types/function%20(id)%20%7B%20%20%20%20%20%20options.id%20=%20id;%20%20%20%20%20%20return%20helpersBase.urlFor.action(options);%20%20%20%20%7D not found. 

我不知道这可能来自哪里。 我查看了代码,什么都没发现。

控制器:

 var ArithmeticProblemTypes = function () { this.respondsWith =[ 'html', 'json', 'xml', 'js', 'txt']; this.index = function (req, resp, params) { var self = this; geddy.model.ArithmeticProblemType.all(function (err, arithmetic_problem_types) { self.respond({ params: params, arithmetic_problem_types: arithmetic_problem_types }); }); }; this.add = function (req, resp, params) { this.respond({ params: params }); }; this.create = function (req, resp, params) { var self = this, arithmetic_problem_type = geddy.model.ArithmeticProblemType.create({ name: '1', title: 'open', numberType: '1', numberRanges: '1', operators: '1', askedFor: '1', specialProblemCategory: '1', askedForNumDenomOrBoth: '1', reducedFractions:'1', mixedFractions: '1' }); arithmetic_problem_type.save(function (err, data) { if (err) { params.errors = err; self.transfer('add'); } else { self.redirect({ controller: self.name }); } }); }; .................................................................... }; exports.ArithmeticProblemTypes = ArithmeticProblemTypes; 

add.html.ejs

 <div class="hero-unit"> <%= partial('_form', {params: params}); %> </div> 

index.html.ejs

 <div class="hero-unit"> <h2>Arithmetic Problem Types List</h2> <%- linkTo('Create a new Aritmetic Problem Type', addArithmeticProblemTypePath, {class: 'btn pull-right'}) %> </div> <% if (arithmetic_problem_types && arithmetic_problem_types.length) { %> <% for (var i in arithmetic_problem_types) { %> <div class="row todo-item"> <div class="span8"> <h3><%- linkTo(arithmetic_problem_types[i].title, arithmeticProblemTypePath(arithmetic_problem_types[i].id)) %></h3> </div> <div class="span4"><h3><i class="icon-list-alt"></i><%= arithmetic_problem_types[i].status; %></h3></div> </div> <% } %> <% } %> 

我怎样才能摆脱这个信息,并使其工作?

编辑:这是_form.html.ejs文件的开始:

 <% var isUpdate = params.action == 'edit' , formTitle = isUpdate ? 'Update this Arithmetic Problem Type' : 'Create a new Arithmetic Problem Type' , action = isUpdate ? arithmeticProblemTypePath(params.id) + '?_method=PUT' : arithmeticProblemTypePath , deleteAction = isUpdate ? arithmeticProblemTypePath(params.id) + '?_method=DELETE' : '' , btnText = isUpdate ? 'Update' : 'Add' , nameValue = isUpdate ? arithmeticProblemTypePath.name : '' , errors = params.errors; %> <form id="arithmetic-problem-type-form" class="form-horizontal" action="<%= action %>" method="POST"> .... </form> 

编辑2:检查页面,我应该写的项目的名称,然后单击添加button,我已经find了这个

 <div class="hero-unit"> <form id="arithmetic-problem-type-form" class="form-horizontal" action="function (id) { options.id = id; return helpersBase.urlFor.action(options); }" method="POST"> <fieldset> <legend>Create a new Arithmetic Problem Type</legend> <div class="control-group"> <label for="title" class="control-label">Title</label> <div class="controls"> <input class="span6" name="name" placeholder="enter name" type="text"> </div> </div> <div class="form-actions"> <input class="btn btn-primary" type="submit" value="Add"> </div> </fieldset> </form> </div> 

事实上,这个消息来自表单元素的action属性,但我该如何解决呢?

该消息告诉你,找不到请求的URL。 又名404

/arithmetic_problem_types/function%20(id)%20%7B%20%20%20%20%20%20options.id%20=%20id;%20%20%20%20%20%20return%20helpersBase.urlFor.action(options);%20%20%20%20%7D

绝对不是一个漂亮的url。 所以我假设你的表单的action属性有问题。 如果这是您validation表单时发生的情况。

如果这是您点击链接到“创build新的算术问题types”时发生的情况,那么您应该在addArithmeticProblemTypePath