Sha256: d12cabfb688d12d90fcf05ae2375c0f0acbe84fe6623407dc8f70c1193be3ad8
Contents?: true
Size: 1.17 KB
Versions: 6
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module Decidim # Redirects users with short links to the correct location on the site. class ShortLinksController < Decidim::ApplicationController skip_before_action :store_current_location # The index action redirects the user to the application root in case # someone tries to request the short link URL without an identifier. def index redirect_to decidim.root_path, status: :moved_permanently end # Redirects the user to the target URL that the short link is set to # redirect to. Raises an ActionController::RoutingError in case a short link # does not exist with the given identifier. # # @raise [ActionController::RoutingError] if a short link does not exist # with the given identifier def show raise ActionController::RoutingError, "Not Found" unless link redirect_to link.target_url, status: :moved_permanently end private # Fetches the link based on the provided identifier in the parameters. # # @return [Decidim::ShortLink] The short link matching the identifier def link @link ||= Decidim::ShortLink.find_by(identifier: params[:id]) end end end
Version data entries
6 entries across 6 versions & 1 rubygems