Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
controller: Merge pull request #4 from flynn/crud-empty-array
Browse files Browse the repository at this point in the history
Render an empty JSON array when crud lists are empty
  • Loading branch information
titanous committed Apr 24, 2014
2 parents 380cb19 + d0ebcc0 commit 6816c06
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crud.go
Expand Up @@ -72,6 +72,10 @@ func crud(resource string, example interface{}, repo Repository, r martini.Route
r.JSON(500, struct{}{})
return
}
// render an empty JSON array (rather than null) if list is nil
if list == nil {
list = []struct{}{}
}
r.JSON(200, list)
})

Expand Down

0 comments on commit 6816c06

Please sign in to comment.