Including a module in a Rails 5 Application Record class
问题 I am using Application Record to simplify shared logic throughout an application. Here's an example that writes a scope for a boolean and its inverse. This works well: class ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.boolean_scope(attr, opposite = nil) scope(attr, -> { where("#{attr}": true) }) scope(opposite, -> { where("#{attr}": false) }) if opposite.present? end end class User < ApplicationRecord boolean_scope :verified, :unverified end class Message <