Can't pass parameter to the view #142

Closed
srad opened this Issue May 13, 2012 · 3 comments

Projects

None yet

3 participants

srad commented May 13, 2012

I have a very very weird issue when I'm trying to pass an argument from a controller to a view.

This works:

  this.show = function (req, resp, params) {
    'use strict';

    var self = this;

    geddy.model.Post.load(params.id, function (err, post) {
      self.respond({ params: params, post: post });
    });
  };

But exactly the same from the edit controller doesn't work:

  this.edit = function (req, resp, params) {
    'use strict';

    var self = this;
    geddy.model.Post.load(params.id, function (err, post) {
      console.log('\n'+JSON.stringify(post)+'\n');
      self.respond({ params: params, post: post });
    });
  };

I get this error within the view:

undefined:4
  , action = update ? '/posts' + post._id + '?_method=PUT' : '/posts'
                                 ^
ReferenceError: post is not defined

Although the "post" object exists within the controller:

{"type":"Post","saved":true,"_id":"4fb0075e356e23fb25000001","title":"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk","content":"kkkkkkkkkkkkkkkkkkkkkkkkkkk"}

"params" is completely fine send to the view.

Version:

$ node -v
v0.6.16

$ geddy -v
0.4.1

Anybody an idea what I've overlooked here?

Contributor
mde commented May 14, 2012

Weird one. We'll take a look -- in the meantime, what happens if you hang "post" as a property on params?

srad commented May 15, 2012

That was also what I thought about, so I did this now:

  this.edit = function (req, resp, params) {
    'use strict';

    var self = this;
    geddy.model.Post.load(params.id, function (err, post) {
      params.post = post;
      self.respond({ params: params });
    });
  };

and it works. I thought the "post" key is overwritten within the "respond" method somewhere, but I couldn't see anything.
But still, probably something overwrites/deletes the property...

Contributor

Has anyone been able to reproduce this? If not, I'm going to close this.

@Techwraith Techwraith closed this Jun 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment