gpt4 book ai didi

node.js - Geddy - 创建新项目

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:31 26 4
gpt4 key购买 nike

我是node.js 和geddy 的绝对初学者。我已经遵循了一些教程,现在我尝试为我的目的写一些类似的东西。

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

/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.

我不知道这可能来自哪里。我查看了代码并没有发现任何结果。

Controller :

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;

添加.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:检查我应该在其中写入项目名称并单击添加按钮的页面,我发现了这个

<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>

消息确实来自form元素的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

绝对不是一个好看的网址。所以我假设您的表单的 action 属性有问题。如果这就是您验证表单时发生的情况。

如果这就是您单击“创建新算术问题类型”链接时发生的情况,那么您可能应该在 addArithmeticProblemTypePath 之后添加括号

关于node.js - Geddy - 创建新项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15229067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com