How to Use Scopes in Ruby on Rails

What is a scope in Rails & why is it useful? Well… Scopes are custom queries that you define inside your Rails models with the scope method. Every scope takes two arguments: It looks like this: As a result of calling a scope, you’ll get an ActiveRecord::Relation object. Which means you can chain & combine … Read more

Ruby Syntax Reference For Beginners

This is a Ruby syntax reference. Learning Ruby can be overwhelming with everything you have to remember. That’s why I put together this syntax reference for you! It will help refresh your memory & quickly review what you need to know to write Ruby programs. Have fun! Contents Strings A string is a sequence of … Read more

How to Use The Ruby Ternary Operator (?:)

What is a ternary operator in Ruby? A ternary operator is made of three parts, that’s where the word “ternary” comes from. These parts include a conditional statement & two possible outcomes. In other words, a ternary gives you a way to write a compact if/else expression in just one line of code. For example: … Read more

Rails Design Patterns: Presenter & Service Objects

Why do we need design patterns? The problem is that Rails architecture, Model-View-Controller, gives you a basic structure to put your code in. But this isn’t enough. Your views grow large & full of logic when their goal is to present information. Your controllers hold details beyond what’s necessary for the controller to do its … Read more