Class: Decidim::ShortLinksController

Inherits:
ApplicationController show all
Defined in:
decidim-core/app/controllers/decidim/short_links_controller.rb

Overview

Redirects users with short links to the correct location on the site.

Instance Method Summary collapse

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#indexObject

The index action redirects the user to the application root in case someone tries to request the short link URL without an identifier.



10
11
12
# File 'decidim-core/app/controllers/decidim/short_links_controller.rb', line 10

def index
  redirect_to decidim.root_path, status: :moved_permanently
end

#showObject

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.

Raises:

  • (ActionController::RoutingError)

    if a short link does not exist with the given identifier



20
21
22
23
24
# File 'decidim-core/app/controllers/decidim/short_links_controller.rb', line 20

def show
  raise ActionController::RoutingError, "Not Found" unless link

  redirect_to link.target_url, status: :moved_permanently
end