Sha256: 44b27d20533fcb800c63f101c84b892a8d64e161df489010e3840403b3c68282
Contents?: true
Size: 591 Bytes
Versions: 15
Compression:
Stored size: 591 Bytes
Contents
# frozen_string_literal: true class UrlRewrite < ApplicationRecord validates :from, :to, presence: true validates :from, format: { with: %r{\A/.*\z}, message: "should start with /" } scope :active, -> { where(active: true) } scope :alphabetical, -> { order(from: :asc) } def to_s "#{from} -> #{to}" end scope :admin_search, ->(query) do where(arel_table[:from].matches("%#{query}%").or(arel_table[:to].matches("%#{query}%"))) end def self.redirect_path_for(path) active.find_by(from: path).try(:to) end def title from.delete_prefix("/") end end
Version data entries
15 entries across 15 versions & 1 rubygems