Skip to content

Commit

Permalink
Merge pull request #539 from unepwcmc/404-page
Browse files Browse the repository at this point in the history
404 page
  • Loading branch information
Levia authored Sep 23, 2020
2 parents 0d32fc5 + fe571d1 commit c3d2a3a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
9 changes: 9 additions & 0 deletions app/assets/stylesheets/pages/_error-page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.error-page {
&__hero {
text-align: center;

& > .hero--basic .hero__content {
width: 100%;
}
}
}
21 changes: 1 addition & 20 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/?}
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions app/views/layouts/404.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<section class="error-page__hero spacer-large--medium">
<%= render partial: "./layouts/partials/hero-basic", locals: {
title: t('global.redirect.title'),
summary: t('global.redirect.text', url: root_url).html_safe
} %>
</section>


<section class="container spacer-small--bottom">
<%= render "partials/cards/articles" %>
</section>

<section class="container spacer-small--top">
<%= render "partials/cards/resources" %>
</section>

<section class="spacer-small--bottom">
<%= render "partials/carousels/themes" %>
</section>

<%= render "partials/ctas/live-report" %>
7 changes: 7 additions & 0 deletions config/initializers/comfy_patching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/locales/global/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=\"%{url}\">homepage</a>."

0 comments on commit c3d2a3a

Please sign in to comment.