diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 98c86602..cd4d0361 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -27,7 +27,7 @@ module ApplicationHelper hover_class_names = [ "hover:bg-white", "hover:border-[#141414]/[0.07]", "hover:text-gray-900", "hover:shadow-xs" ] current_page_class_names = [ "bg-white", "border-[#141414]/[0.07]", "text-gray-900", "shadow-xs" ] - link_class_names = if current_page?(path) + link_class_names = if is_current_path?(path) base_class_names.delete("border-transparent") base_class_names + hover_class_names + current_page_class_names else @@ -41,6 +41,22 @@ module ApplicationHelper end end + def is_current_path?(path) + # Return false immediately if the path is a placeholder + return false if path == "#" + + begin + # Extract the controller and action from the given path. + recognize_path = Rails.application.routes.recognize_path(path) + # Compare the recognized path's controller to the current controller. + # If they match, it means the given path is for the current page. + recognize_path[:controller] == controller_name + rescue ActionController::RoutingError + # If the path is not recognized catch the exception and return false. + false + end + end + def format_currency(number, options = {}) user_currency_preference = Current.family.try(:currency) || "USD"