An open API service indexing awesome lists of open source software.

https://github.com/justalever/scopes_101


https://github.com/justalever/scopes_101

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

![How to use Scopes in Ruby on Rails](https://f001.backblazeb2.com/file/webcrunch/scopes-ruby-on-rails.jpg)

# How to use Scopes in Ruby on Rails

_This is a repo based on a quick guide I created on my blog and YouTube channel_

Scopes are used to assign complex ActiveRecord queries into customized methods using Ruby on Rails.

Inside your models, you can define a scope as a new method that returns a lambda function for calling queries you're probably used to using inside your controllers.

A use case for scopes is often for filtering by status, date, date ranges, ordering, groupings, and more. ActiveRecord already makes it quite easy to return rich data from your database. Combining those superpowers with scopes allow you to define more memorable queries that you and your team can harness through your Ruby on Rails application.

Read the entire blog post here:
[https://web-crunch.com/posts/how-to-use-scopes-ruby-on-rails](https://web-crunch.com/posts/how-to-use-scopes-ruby-on-rails)