Ruby on rails 在haml视图中重构条件
除此之外,无障碍标准不鼓励使用 一个指向当前页面的链接,我应该怎么做 重构以下视图代码Ruby on rails 在haml视图中重构条件,ruby-on-rails,ruby,haml,Ruby On Rails,Ruby,Haml,除此之外,无障碍标准不鼓励使用 一个指向当前页面的链接,我应该怎么做 重构以下视图代码 #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("n
#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
...
谢谢。看来这是一个很好的理由来支持我。如果你要投反对票,请发表评论。否则你就不会加入讨论——你只是一个混蛋。在这里,部分内容肯定会有所帮助,但你相当含糊。一个关于该部分具体内容的建议会有所帮助。谢谢!三元运算器更简洁,但我很想得到一个函数,非常好!非常感谢。附言:我想我可以放弃函数中的最后一个返回,不是吗?没错;我添加它是为了与另一个
return
对称,并强调散列作为返回值存在。
#navigation
%ul.tabbed
%li{:class => current_page?(new_profile_path) ? "current_page_item" :nil }
= link_to t("new_profile"), new_profile_path
%li{:class => current_page?(profiles_path) ? "current_page_item" :nil }
= 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
...