feat: customized page 404

This commit is contained in:
Colin Darie 2024-03-28 09:45:05 +01:00
parent fe508c0a73
commit 7dcd4ba538
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
11 changed files with 149 additions and 77 deletions

View file

@ -419,6 +419,17 @@ class ApplicationController < ActionController::Base
prepend_view_path "app/custom_views"
end
def try_nav_bar_profile_from_referrer
# detect context from referer, simple (no detection when refreshing the page)
params = Rails.application.routes.recognize_path(request&.referer)
controller_class = "#{params[:controller].camelize}Controller".safe_constantize
return if controller_class.nil?
controller_instance = controller_class.new
controller_instance.try(:nav_bar_profile)
end
# Extract a value from params based on the "path"
#
# params: { dossiers: { champs_public_attributes: { 1234 => { value: "hello" } } } }

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class ErrorsController < ApplicationController
def nav_bar_profile = try_nav_bar_profile_from_referrer
def not_found
render(status: 404)
end
end

View file

@ -21,16 +21,7 @@ class ReleaseNotesController < ApplicationController
render "scrollable_list" if params[:page].present?
end
def nav_bar_profile
# detect context from referer, simple (no detection when refreshing the page)
params = Rails.application.routes.recognize_path(request&.referer)
controller_class = "#{params[:controller].camelize}Controller".safe_constantize
return if controller_class.nil?
controller_instance = controller_class.new
controller_instance.try(:nav_bar_profile)
end
def nav_bar_profile = try_nav_bar_profile_from_referrer
private