diff --git a/app/assets/stylesheets/pages/_error-page.scss b/app/assets/stylesheets/pages/_error-page.scss new file mode 100644 index 000000000..ba168efa4 --- /dev/null +++ b/app/assets/stylesheets/pages/_error-page.scss @@ -0,0 +1,9 @@ +.error-page { + &__hero { + text-align: center; + + & > .hero--basic .hero__content { + width: 100%; + } + } +} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9a298a92b..3740d1485 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,7 +14,6 @@ class PageNotFound < StandardError; end; before_action :set_locale before_action :check_for_pdf - after_action :store_location def admin_path? request.original_fullpath =~ %r{/(?:#{I18n.locale}/)?admin/?} @@ -113,31 +112,13 @@ def is_comfy_page_edit? end def render_404 - render file: Rails.root.join("/public/404.html"), layout: false, status: :not_found + render file: Rails.root.join("/app/views/layouts/404.html.erb"), layout: true, status: :not_found end - NO_REDIRECT = [ - "/users/sign_in", - "/users/sign_up", - "/users/password/new", - "/users/password/edit", - "/users/confirmation", - "/users/sign_out" - ] - def check_for_pdf @for_pdf = params[:for_pdf].present? end - def store_location - # store last url - this is needed for post-login redirect to whatever the user last visited. - return unless request.get? - - if (!NO_REDIRECT.include?(request.path) && !request.xhr?) - session[:previous_url] = request.fullpath - end - end - def set_host_for_local_storage Rails.application.routes.default_url_options[:host] = request.base_url if Rails.application.config.active_storage.service == :local # TODO Check why this is not set automatically diff --git a/app/views/layouts/404.html.erb b/app/views/layouts/404.html.erb new file mode 100644 index 000000000..b5fb3ba31 --- /dev/null +++ b/app/views/layouts/404.html.erb @@ -0,0 +1,21 @@ +
+ <%= render partial: "./layouts/partials/hero-basic", locals: { + title: t('global.redirect.title'), + summary: t('global.redirect.text', url: root_url).html_safe + } %> +
+ + +
+ <%= render "partials/cards/articles" %> +
+ +
+ <%= render "partials/cards/resources" %> +
+ +
+ <%= render "partials/carousels/themes" %> +
+ +<%= render "partials/ctas/live-report" %> \ No newline at end of file diff --git a/config/initializers/comfy_patching.rb b/config/initializers/comfy_patching.rb index 3eb3d4074..10662f8a7 100644 --- a/config/initializers/comfy_patching.rb +++ b/config/initializers/comfy_patching.rb @@ -238,4 +238,11 @@ def construct_fragments_attributes(hash, record, path) [frag_identifiers, frag_attributes] end end + + Comfy::Cms::ContentController.class_eval do + # Needed for redirects for CMS pages (essentially anything with a locale) + def load_cms_page + raise_404 unless find_cms_page_by_full_path("/#{params[:cms_path]}") + end + end end \ No newline at end of file diff --git a/config/locales/global/en.yml b/config/locales/global/en.yml index 9fe5c871e..9c6e60647 100644 --- a/config/locales/global/en.yml +++ b/config/locales/global/en.yml @@ -33,3 +33,6 @@ en: search-site: Search... status: updated: Updated + redirect: + title: Sorry, that page can't be found. + text: "Feel free to browse the themes and articles below, or go back to the homepage." \ No newline at end of file