Sha256: dd799944eef1a0b2554c0928537d8b2aef2b08514d3c9fde864ff9b0b76085a4
Contents?: true
Size: 894 Bytes
Versions: 1
Compression:
Stored size: 894 Bytes
Contents
# encoding: utf-8 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_nil: true, 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pages_core-3.5.1 | app/models/concerns/pages_core/page_model/redirectable.rb |