Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.
/ any Public archive

Super easy way to get a random model instance from an Active Record model.

License

Notifications You must be signed in to change notification settings

soffes/any

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Any

Any provides a super easy way to get a random model instance from an Active Record model.. This is really handy when testing or populating your database with dummy data.

Usage

Say you have a model named Post and you want a random instance of it, all you have to do is:

Post.any

If you don't have any posts, it will return nil instead.

Due to the awesomeness of Rails 3, you can chain it to stuff like:

User.where("username != 'sam'").any

That would give you one random user who's username isn't sam. Pretty handy stuff.

About

Super easy way to get a random model instance from an Active Record model.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages