From 804e76160256e52f820226fcccd159c6b4d23eab Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Mon, 21 Sep 2020 14:34:21 +0100 Subject: [PATCH 1/7] diverted 404 render in application controller --- app/controllers/application_controller.rb | 12 ++++++------ app/views/layouts/404.html | 0 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 app/views/layouts/404.html diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b79d27833..09763837c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -54,11 +54,11 @@ def set_locale end def raise_404 - raise PageNotFound - end - - rescue_from PageNotFound do - render_404 + begin + raise PageNotFound + rescue_from PageNotFound do + render_404 + end end def enable_caching @@ -113,7 +113,7 @@ 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"), layout: false, status: :not_found end NO_REDIRECT = [ diff --git a/app/views/layouts/404.html b/app/views/layouts/404.html new file mode 100644 index 000000000..e69de29bb From b2a68df1f83bc5bbc7f483893e27ee20441a81ae Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Wed, 23 Sep 2020 13:08:35 +0100 Subject: [PATCH 2/7] fleshed out 404 page layout and content, updated redirect array in app controller --- app/controllers/application_controller.rb | 18 +++++++++--------- app/views/layouts/404-content.html | 4 ++++ app/views/layouts/404.html | 17 +++++++++++++++++ config/locales/global/en.yml | 3 +++ 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 app/views/layouts/404-content.html diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09763837c..4c6c6924a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,6 +16,14 @@ class PageNotFound < StandardError; end; before_action :check_for_pdf after_action :store_location + NO_REDIRECT = ["/users/sign_in", + "/users/sign_up", + "/users/password/new", + "/users/password/edit", + "/users/confirmation", + "/users/sign_out" + ].freeze + def admin_path? request.original_fullpath =~ %r{/(?:#{I18n.locale}/)?admin/?} end @@ -116,15 +124,6 @@ def render_404 render file: Rails.root.join("/app/views/layouts/404.html"), layout: false, 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 @@ -144,3 +143,4 @@ def set_host_for_local_storage ActiveStorage::Current.host = request.base_url if Rails.application.config.active_storage.service == :local end end +end \ No newline at end of file diff --git a/app/views/layouts/404-content.html b/app/views/layouts/404-content.html new file mode 100644 index 000000000..4cadb9163 --- /dev/null +++ b/app/views/layouts/404-content.html @@ -0,0 +1,4 @@ +
+

<%= t('global.redirect.title') %>

+

<%= t('global.redirect.text', url: root_path) %>

+
\ No newline at end of file diff --git a/app/views/layouts/404.html b/app/views/layouts/404.html index e69de29bb..c2ade11a4 100644 --- a/app/views/layouts/404.html +++ b/app/views/layouts/404.html @@ -0,0 +1,17 @@ +
+ <%= render "layouts/404-content" %> +
+ +
+ <%= 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/locales/global/en.yml b/config/locales/global/en.yml index 9fe5c871e..577c2cf8f 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 doesn't exist. + text: "Feel free to browse the themes and articles below, or go back to the homepage" \ No newline at end of file From 84dcb73b895f0b074cd609014164059cf42fd74f Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Wed, 23 Sep 2020 13:19:09 +0100 Subject: [PATCH 3/7] formatting and naming changes --- app/controllers/application_controller.rb | 13 ++++++------- app/views/layouts/{404.html => 404.html.erb} | 0 .../{404-content.html => _404-content.html.erb} | 0 3 files changed, 6 insertions(+), 7 deletions(-) rename app/views/layouts/{404.html => 404.html.erb} (100%) rename app/views/layouts/{404-content.html => _404-content.html.erb} (100%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 82f6e0cae..a42e68112 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -62,11 +62,11 @@ def set_locale end def raise_404 - begin - raise PageNotFound - rescue_from PageNotFound do - render_404 - end + raise PageNotFound + end + + rescue_from PageNotFound do + render_404 end def enable_caching @@ -121,7 +121,7 @@ def is_comfy_page_edit? end def render_404 - render file: Rails.root.join("/app/views/layouts/404.html"), layout: false, status: :not_found + render file: Rails.root.join("/app/views/layouts/404.html.erb"), layout: false, status: :not_found end def check_for_pdf @@ -143,4 +143,3 @@ def set_host_for_local_storage ActiveStorage::Current.host = request.base_url if Rails.application.config.active_storage.service == :local end end -end \ No newline at end of file diff --git a/app/views/layouts/404.html b/app/views/layouts/404.html.erb similarity index 100% rename from app/views/layouts/404.html rename to app/views/layouts/404.html.erb diff --git a/app/views/layouts/404-content.html b/app/views/layouts/_404-content.html.erb similarity index 100% rename from app/views/layouts/404-content.html rename to app/views/layouts/_404-content.html.erb From fe168817350c532f6555ce77389cc2b6f368a6ae Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Wed, 23 Sep 2020 16:26:33 +0100 Subject: [PATCH 4/7] 404 page now uses css, and redirects correctly for CMS pages --- app/controllers/application_controller.rb | 2 +- app/views/layouts/_404-content.html.erb | 4 ++-- config/initializers/comfy_patching.rb | 7 +++++++ config/locales/global/en.yml | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a42e68112..85325ddda 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -121,7 +121,7 @@ def is_comfy_page_edit? end def render_404 - render file: Rails.root.join("/app/views/layouts/404.html.erb"), layout: false, status: :not_found + render file: Rails.root.join("/app/views/layouts/404.html.erb"), layout: true, status: :not_found end def check_for_pdf diff --git a/app/views/layouts/_404-content.html.erb b/app/views/layouts/_404-content.html.erb index 4cadb9163..5a63843bd 100644 --- a/app/views/layouts/_404-content.html.erb +++ b/app/views/layouts/_404-content.html.erb @@ -1,4 +1,4 @@
-

<%= t('global.redirect.title') %>

-

<%= t('global.redirect.text', url: root_path) %>

+

<%= t('global.redirect.title') %>

+

<%= t('global.redirect.text', url: root_url).html_safe %>

\ 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 577c2cf8f..9c6e60647 100644 --- a/config/locales/global/en.yml +++ b/config/locales/global/en.yml @@ -34,5 +34,5 @@ en: status: updated: Updated redirect: - title: Sorry, that page doesn't exist. - text: "Feel free to browse the themes and articles below, or go back to the homepage" \ No newline at end of file + 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 From 331270fbc5aa9e0ec16f483a96faafbcbd8df192 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Wed, 23 Sep 2020 17:16:10 +0100 Subject: [PATCH 5/7] moved text into hero, increased space between hero and rest of page --- app/views/layouts/404.html.erb | 8 ++++++-- app/views/layouts/_404-content.html.erb | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 app/views/layouts/_404-content.html.erb diff --git a/app/views/layouts/404.html.erb b/app/views/layouts/404.html.erb index c2ade11a4..f7d447e5e 100644 --- a/app/views/layouts/404.html.erb +++ b/app/views/layouts/404.html.erb @@ -1,7 +1,11 @@ -
- <%= render "layouts/404-content" %> +
+ <%= 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" %>
diff --git a/app/views/layouts/_404-content.html.erb b/app/views/layouts/_404-content.html.erb deleted file mode 100644 index 5a63843bd..000000000 --- a/app/views/layouts/_404-content.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -
-

<%= t('global.redirect.title') %>

-

<%= t('global.redirect.text', url: root_url).html_safe %>

-
\ No newline at end of file From 6348edf56dc59a3c562484f7a50b67eb704c6d8b Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Wed, 23 Sep 2020 17:21:59 +0100 Subject: [PATCH 6/7] centred text in hero --- app/assets/stylesheets/pages/_error-page.scss | 9 +++++++++ app/views/layouts/404.html.erb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/pages/_error-page.scss 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/views/layouts/404.html.erb b/app/views/layouts/404.html.erb index f7d447e5e..b5fb3ba31 100644 --- a/app/views/layouts/404.html.erb +++ b/app/views/layouts/404.html.erb @@ -1,4 +1,4 @@ -
+
<%= render partial: "./layouts/partials/hero-basic", locals: { title: t('global.redirect.title'), summary: t('global.redirect.text', url: root_url).html_safe From fe571d1d14574bb08e05494fb52542c256a976d6 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Wed, 23 Sep 2020 18:19:39 +0100 Subject: [PATCH 7/7] remove redundant method and global variable from controller --- app/controllers/application_controller.rb | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 85325ddda..3740d1485 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,15 +14,6 @@ class PageNotFound < StandardError; end; before_action :set_locale before_action :check_for_pdf - after_action :store_location - - NO_REDIRECT = ["/users/sign_in", - "/users/sign_up", - "/users/password/new", - "/users/password/edit", - "/users/confirmation", - "/users/sign_out" - ].freeze def admin_path? request.original_fullpath =~ %r{/(?:#{I18n.locale}/)?admin/?} @@ -128,15 +119,6 @@ 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