Geddy - 创造新项目

时间:2013-03-05 16:28:35

标签: node.js geddy

我是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.

我不知道这可能来自哪里。我查看了代码并没有找到任何内容。

控制器:

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>

EDIT2: 检查我应该在哪里写下项目名称的页面,然后点击添加按钮,我发现了这个

<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属性,但我该如何解决呢?

1 个答案:

答案 0 :(得分:1)

该消息告诉您无法找到请求的URL。 AKA 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之后加上括号