Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Quick named scopes to make your life a little easier

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .autotest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
Octocat-spinner-32 quick_scopes.gemspec
README.rdoc

A Rails plugin to automatically add some quick named_scopes to your models.

These are especially useful for quick modifications to a query on an association.

The named_scopes

The named scopes added are:

  • order

  • limit

  • offset

  • with - alias for :include

  • where - alias for :conditions

Examples

With a User model having many Posts

# Standard association method to retrieve all posts
user.posts

# Order the posts
user.posts.order('created_at')

# Limit the results to a specific number
user.posts.limit(5)

# Offset the results
user.posts.offset(5)

# Include other associated models
user.posts.with(:comments)
user.posts.with(:comments, :author)
user.posts.with({:comments => :author}, :author)

# Limit your results with conditions
user.posts.where(:published => true)

Note

Some of these don't promote best practices for your code but can be very useful when working with the console.

Something went wrong with that request. Please try again.