![](/img/trans.png)
[英]Ruby on Rails: looping through records, but don't show record from current id
[英]Ruby on Rails: if current page? is homepage, don't show form
我不想顯示表單,但前提是當前頁面不是主頁
這是我到目前為止...
我有我的路線設置:
root 'projects#index'
我的看法:
<% if !current_page?(url_for(:controller => 'projects', :action => 'index')) %>
show some stuff
<% end %>
這不會顯示 url 是否為localhost:3000/projects
但它顯示了它的localhost:3000
所以我需要以某種方式確保如果它是主頁,它就不會顯示。 另外,我有主頁的搜索參數,但我仍然不想顯示它是否像localhost:3000/projects?search=blahblahblah
使用root_path
助手:
<% unless current_page?(root_path) %>
show some stuff
<% end %>
這不會顯示 url 是否是
localhost:3000/projects
但它會顯示它的localhost:3000
或者:
<% unless current_page?('/') || current_page?('/projects') %>
# '/' the same as root_path
show some stuff
<% end %>
另外,根據documentation
,不需要url_for
方法:
current_page?(controller: 'projects', action: 'index')
如果unless current_page?(root_path)
不適合你,請檢查你的root_path
是否有額外參數,我有一個額外參數,因此它無法正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.