如何在子元素上设置 active_link_to 以仅设置为活动?
How to set active_link_to on child elements to set active only?
我是 rails 的新手,我只想在子元素上设置 active_link_to
。我正在使用这个 gem https://github.com/comfy/active_link_to
情况:
parent element path:
localhost:3000/columns // This one is set to active when going to that specific page
child element path:
localhost:3000/columns/post // This one will also be active also but the parent element is also active
我有这个导航栏:
<ul class="nav-bar">
<li class="nav-item">
<%= active_link_to columns_root_path, :class => 'nav-link' do %>
Columns
<% end %>
</li>
<li class="nav-item">
<%= active_link_to columns_post_path, :class => 'nav-link' do %>
Post
<% end %>
</li>
</ul>
如果我只转到子元素,如何删除父元素中的active_link_to
。因为在我的情况下,当我转到这条路径时:localhost:3000/columns/post
columns
和 post
路径都将设置为活动。
我的路线文件中有这里。
routes.rb
namespace :columns do
root 'columns#index', as: "root"
get 'post' => 'post#index'
end
通常我把文件夹设置成这个:
app/views/columns/columns/index.html.erb //for the columns index
app/views/columns/post/index.html.erb //for the post index
我不熟悉 active_link_to
gem。但是重新阅读文档,我猜 active: :exact
选项就是您要查找的内容。
<ul class="nav-bar">
<li class="nav-item">
<%= active_link_to columns_root_path, active: :exact, :class => 'nav-link' do %>
Columns
<% end %>
</li>
<li class="nav-item">
<%= active_link_to columns_post_path, active: :exact, :class => 'nav-link' do %>
Post
<% end %>
</li>
</ul>
我是 rails 的新手,我只想在子元素上设置 active_link_to
。我正在使用这个 gem https://github.com/comfy/active_link_to
情况:
parent element path:
localhost:3000/columns // This one is set to active when going to that specific page
child element path:
localhost:3000/columns/post // This one will also be active also but the parent element is also active
我有这个导航栏:
<ul class="nav-bar">
<li class="nav-item">
<%= active_link_to columns_root_path, :class => 'nav-link' do %>
Columns
<% end %>
</li>
<li class="nav-item">
<%= active_link_to columns_post_path, :class => 'nav-link' do %>
Post
<% end %>
</li>
</ul>
如果我只转到子元素,如何删除父元素中的active_link_to
。因为在我的情况下,当我转到这条路径时:localhost:3000/columns/post
columns
和 post
路径都将设置为活动。
我的路线文件中有这里。 routes.rb
namespace :columns do
root 'columns#index', as: "root"
get 'post' => 'post#index'
end
通常我把文件夹设置成这个:
app/views/columns/columns/index.html.erb //for the columns index
app/views/columns/post/index.html.erb //for the post index
我不熟悉 active_link_to
gem。但是重新阅读文档,我猜 active: :exact
选项就是您要查找的内容。
<ul class="nav-bar">
<li class="nav-item">
<%= active_link_to columns_root_path, active: :exact, :class => 'nav-link' do %>
Columns
<% end %>
</li>
<li class="nav-item">
<%= active_link_to columns_post_path, active: :exact, :class => 'nav-link' do %>
Post
<% end %>
</li>
</ul>