我正在设置我的导航栏$scope.$apply(function () {
//your code
});
$scope.$apply(function () {
$scope.dataAcData
});
go through http://jimhoskins.com/2012/12/17/angularjs-and-apply.html link, Hope it will help you
,如果current_path与link_path相同或者当前路径与根路径相同,我试图停止呈现链接,因为根路径定义为与链接路径相同,如下所示:
_navbarhtml.erb
link_to
的routes.rb
<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>
关于如何很好地写这个的任何巧妙的建议?
答案 0 :(得分:1)
您可以尝试current_page?
。创建一个这样的辅助方法:
def link_to_unless_current(text, url, options={})
if current_page?(url)
# do something else? maybe create a text which does not have a link?
else
link_to text, url, options
end
end
现在,视图将如下:
<%= link_to_unless_current('My Quotes', quotes_path(current_user)) %>
随意更改辅助方法的名称。
答案 1 :(得分:0)
感谢Surya,这是我最终让它发挥作用的方式:
application_helper.rb
def link_to_unless_current_or_root(text, url)
if current_page?(url)
elsif current_page?(root_path)
else
link_to text, url
end
end
_navbar.html.erb
<li><%= link_to_unless_current_or_root('New Quote', new_quote_path) %></li>