1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Fix active class assignment in sidebar links

This commit is contained in:
Mattia Malnis 2024-02-12 21:25:53 +01:00
parent 02ce81ba40
commit 55924f32db

View file

@ -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"