Sha256: a56c69488275f1039d48992f3069236a141490acca54e1cbc154f82280e3fd8b
Contents?: true
Size: 862 Bytes
Versions: 28
Compression:
Stored size: 862 Bytes
Contents
# frozen_string_literal: true module PagesCore module PageModel class InvalidRedirectUrl < StandardError; end module Redirectable extend ActiveSupport::Concern included do validates(:redirect_to, format: { with: %r{\A(/|https?://).+\z}, allow_blank: true }) end # Returns boolean true if page has a valid redirect def redirects? redirect_to? end def redirect_path(params = {}) path = redirect_to.dup if path.start_with? "/" params.each do |key, value| unless value.is_a?(String) || value.is_a?(Symbol) raise InvalidRedirectUrl, "must be a string or a symbol" end path.gsub!("/:#{key}", "/#{value}") end end path end end end end
Version data entries
28 entries across 28 versions & 1 rubygems