On Sep 10, 3:41 pm, waugust <[email protected]> wrote:
> This is driving me nuts..
> I have a route mapped as an extra collection on a resource:
> maps.resource('post', 'posts', collection={'json':'GET'})
>
> The controller action:
> @jsonify
> def json(self):
>  q = sa.query(Post)
>         count = q.count()
>         posts = q.all()
>
>         items = []
>         for post in posts:
>             _post =
> {'id':post.id,'caption':post.title,'description':post.content}
>             items.append(_post)
>
>         postsJson = {'posts': count,'items':items}
>
>         return postsJson
>
> Returns null... the code in a shell returns the structure fine (the
> data set isn't empty).
>
> What makes this even stranger is that if I were to map this as a
> member, and pass it an Id - I get a response as expected (even though
> i didn't change the code, other then adding the id parameter).
>
> Anybody know what's going on?
> When trying app.get(url('json_posts')) in the shell I get "<Response
> 200 OK ''>" (null).
> I also get that same response if I put an invalid url in there
> (instead of a 404)...
> The url('json_posts') resolves correctly and paster routes reports it
> appropriately as well.

I'm not really sure what's going on there, but when you use
map.resource, you can do this instead of adding a special `json`
action:

    GET /post/1.json

Then 'json' will be passed as the `format` arg to the appropriate REST
action. In this example:

    def show(self, id, format='html'):
        # id is '1' and format is 'json'
        # ...
        if format == 'json':
            # convert member to json and return it

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to