How To Use Named Scopes In Rails

Written by Nonso | Published 2019/10/19
Tech Story Tags: software-development | latest-tech-stories | coding | development | learning | learning-to-code | ruby

TLDR Named Scopes are a subset of a collection and are lazy loaded. They are used when you do not have extra processing to perform on the retrieved data. Scope is a nice utility and helps keep our codes clean readable and simple. Let's see an example of scope chaining to build complex queries like this: User.confirmed.name('Nonso') This is a very simple example. The class file will look like this. The defined scopes above will be chained like:glyglyUser.confirmed('nonso')via the TL;DR App

no story

Written by Nonso | Software Developer @Bitsfield Tech
Published by HackerNoon on 2019/10/19