Resource Count
Added by Soleone
at October 25, 2009 16:12
GitHub stats:
watcher(s)
fork(s)
About
Extend your RESTful controllers by simply returning the number of models in the database for any call to a URL like modelname/count.
Details
Extend your RESTful controllers by simply returning the number of models in the database for any call to a URL like modelname/count.
Examples:
/users/count
returns User.count in plain text
/articles/1/comments/count.xml
returns Comment.count as XML, e.g.
<comments type="integer">5</comments>
Note: this does not return Articles.find(1).comments.count like it maybe should!
Usage
Simply require in environment.rb with:
config.middleware.use "ResourceCount"
Requirements when not using Rails:
- Use Rails conventions (controller name is pluralized name of model)
- Model.count should be available, but size or length also works
- These String methods from Rails need to be available: singularize, classify and constantize
