gpt4 book ai didi

ruby-on-rails - 多级菜单,事件链接 css 突出显示。 (Rails 上的 ruby )

转载 作者:行者123 更新时间:2023-11-27 22:34:56 24 4
gpt4 key购买 nike

网站结构:

/
/products
/products/design
/products/photo
/about

我想看到当子项处于事件状态时,父菜单项也由 CSS 突出显示。

(当“设计”或“照片”处于事件状态时,“产品”也应突出显示。)

我将其用于子网址和简单网址:

<li class="<%= current_page?(:action => 'design') %>">
<%= link_to_unless_current 'Design', :design %>
</li>

对于“产品”检查应该是这样的:

<%= current_page?(:action => 'products') ||
current_page?(:action => 'design') %> ||
current_page?(:action => 'photo') %>

但是三重||不对,变得复杂了。

我看到了一个 helper ,就像这个:

def current(childs)
if current_page?(:action => childs)
@container = "active"
else
@container = "inactive"
end
end

由以下人员使用:<%= current(:photo) %>

那么,如何将“产品”、“设计”、“照片”这 3 项检查全部放在一个助手中?

并使使用类似 <%= current(:products, :design, :photo) %> 的东西成为可能

最佳答案

我不会重新创建轮子并使用 Rails menu-buildersimple-navigation 这样的 gem/插件.

这是一个 demo of navigation and styling.

关于ruby-on-rails - 多级菜单,事件链接 css 突出显示。 (Rails 上的 ruby ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2798144/

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