Code Explainers

Ruby on Rails code explainers

ruby
class ProductCatalog
  def featured_products
    Rails.cache.fetch("catalog/featured_products", expires_in: 12.hours) do
      Product.where(featured: true)

Caching patterns with Rails.cache.fetch

caching cache-keys expiry
Intermediate 5 steps
ruby
class RegistrationForm
  include ActiveModel::Model
  include ActiveModel::Attributes
 

How a Rails form object spans two models

form object validations transactions
Intermediate 7 steps