【发布时间】:2017-06-19 17:51:03
【问题描述】:
我正在设置我的导航栏link_to,如果 current_path 与 link_path 相同或当前路径与根路径相同,我试图停止呈现链接,因为根路径被定义为与链接路径相同,如下:
_navbarhtml.erb
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in? %>
<li><%= link_to_unless_current('My Quotes', quotes_path(current_user)) do %></li>
<% end %>
<li><%= link_to_unless_current('New Quote', new_quote_path) do %></li>
<% end %>
<li><%= link_to('My Account', edit_user_registration_path) %></li>
<li><%= link_to "Sign out", destroy_user_session_path, :method => :delete %></li>
<% else %>
<li><%= link_to('Sign in', new_user_session_path) %></li>
<li><%= link_to('Sign up', new_user_registration_path) %></li>
<% end %>
</li>
routes.rb
root 'quotes#new'
关于如何写好这篇文章有什么好的建议吗?
【问题讨论】:
-
感谢您的链接,一个很好的解决方案,我想尝试使用 rails helper 来做到这一点,最后我写了一个如下所示的帮助方法,并由@Surya 建议
标签: ruby-on-rails actionviewhelper