mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-26 00:29:40 +02:00
Fix active class assignment in sidebar links
This commit is contained in:
parent
02ce81ba40
commit
55924f32db
1 changed files with 17 additions and 1 deletions
|
@ -27,7 +27,7 @@ module ApplicationHelper
|
||||||
hover_class_names = [ "hover:bg-white", "hover:border-[#141414]/[0.07]", "hover:text-gray-900", "hover:shadow-xs" ]
|
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" ]
|
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.delete("border-transparent")
|
||||||
base_class_names + hover_class_names + current_page_class_names
|
base_class_names + hover_class_names + current_page_class_names
|
||||||
else
|
else
|
||||||
|
@ -41,6 +41,22 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
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 = {})
|
def format_currency(number, options = {})
|
||||||
user_currency_preference = Current.family.try(:currency) || "USD"
|
user_currency_preference = Current.family.try(:currency) || "USD"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue