gpt4 book ai didi

ruby-on-rails - 在 haml View 中重构条件

转载 作者:数据小太阳 更新时间:2023-10-29 07:12:32 26 4
gpt4 key购买 nike

除了可访问性标准不鼓励使用这一事实指向当前页面的链接,我应该怎么做重构以下 View 代码?

#navigation
%ul.tabbed
- if current_page?(new_profile_path)
%li{:class => "current_page_item"}
= link_to t("new_profile"), new_profile_path
- else
%li
= link_to t("new_profile"), new_profile_path

- if current_page?(profiles_path)
%li{:class => "current_page_item"}
= link_to t("profiles"), profiles_path
- else
%li
= link_to t("profiles"), profiles_path
...

谢谢。

最佳答案

# helpers
def current_page_class(page)
return :class => "current_page_item" if current_page?(page)
return {}
end

-# Haml
#navigation
%ul.tabbed
%li{current_page_class(new_profile_path)}
= link_to t("new_profile"), new_profile_path
%li{current_page_class(profiles_path)}
= link_to t("profiles"), profiles_path
...

关于ruby-on-rails - 在 haml View 中重构条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1367876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com