RSSAmplifier

Andy Croll · Mar 9, 2026

Group Repeated Options with with_options

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

When multiple validations share the same if: condition, or multiple callbacks share the same only: constraint, you end up repeating yourself. with_options groups them together. Instead of… …repeating conditions across multiple validations: class Article < ApplicationRecord validates :title , presence: true , if: :published? validates :body , length: { minimum: 100 }, if: :published? validates…

Read on andycroll.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.