Skip to content

Instantly share code, notes, and snippets.

@dskecse
Created January 18, 2021 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dskecse/f6ba46cdbd175d36a80a91ddf1c0afd0 to your computer and use it in GitHub Desktop.
Save dskecse/f6ba46cdbd175d36a80a91ddf1c0afd0 to your computer and use it in GitHub Desktop.
Positionable module/concern
module Positionable
extend ActiveSupport::Concern
included do
scope :by_position, -> { order("#{table_name}.position ASC") }
# or default_scope
end
end
@dskecse
Copy link
Author

dskecse commented Jan 18, 2021

Usage example:

class BlockContent < ApplicationRecord
  include Positionable

  belongs_to :block
end

block = Block.first!
block.block_contents.by_position

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment