My model isn't creating objects and failing silently


I'm running a standard geddy setup with mongo.




// invokes the form for submitting a new url
// sends form output to the create function
this.add = function (req, resp, params) {
    this.respond({params: params});

// creates a new url object and saves it to the database
this.create = function (req, resp, params) {
    var self = this;
    var timestamp = new Date().getTime();
    var url = geddy.model.Url.create({
        title: params.title, 
        url: params.url,
        score: 0,
        created: timestamp
    });, data) {
        if (err) {
            params.errors = err;
        } else {
            this.redirect({controller: 'Url.index'});


var Url = function () {
        title:   {type:'string', required:true},
        url:     {type:'string', required:true},
        score:   {type:'int', required:true},
        created: {type:'datetime', required:true}


Url = geddy.model.register('Url', Url);


<div class="row">
<form class="form-horizontal" role="form" action="/create" method="POST">
    <div class="form-group">
        <label for="title" class="col-lg-1 control-label">Title</label>
        <div class="col-lg-7">
            <input type="text" class="form-control" id="title" placeholder="title">
    <div class="form-group">
        <label for="url" class="col-lg-1 control-label">URL</label>
        <div class="col-lg-7">
            <input type="text" class="form-control" id="url" placeholder="url">
    <div class="form-group">
        <div class="col-lg-offset-1 col-lg-7">
            <button type="submit" class="btn btn-default">Submit</button>

When I visit /submit and fill out the form, I just get redirected to the same form again. Nothing gets inserted in the database. This is my first time using geddy so I'm probably missing something.

Problem courtesy of: n0pe


It looks like you are not printing out the error in your view, so you can't see why it failed.

From the looks of it, it's failing because required variables are missing. You'll need name attributes on your form fields, not just id, or the server will never get your values.

Solution courtesy of: Ben


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.