Question

I am an absolute beginner in node.js and geddy. I've followed a few tutorials and now I try to write something similar for my purposes.

When I try to create a new item, though, I get the following message:

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

I have no idea where this could come from. I've looked through the code and found nothing.

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;

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

How can I get rid of that message and make it work?

EDIT: This is the beginning of the _form.html.ejs file:

<%
  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: Inspecting the page where I should write the name of the item and click the add button, I've found this

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

Indeed the message comes from the action attribute of the form element, but how can I solve it?

Était-ce utile?

La solution

The message is telling you that the requested URL could not be found. 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

is definitely not a nice looking url. So i'm assuming there's something wrong with your form's action attribute. If that's what happened when you validate the form.

If that's what happened when you click the link to "Create a new arithmetic problem type" then you should probably put parenthesis after addArithmeticProblemTypePath

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top