gpt4 book ai didi

ruby-on-rails - Ruby on Rails : if current page? 是主页,不显示表单

转载 作者:数据小太阳 更新时间:2023-10-29 07:09:08 27 4
gpt4 key购买 nike

我不想显示表单,但前提是当前页面不是主页

这是我目前所拥有的...

我有我的路线设置:

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 %>

This doesn't show if the url is localhost:3000/projects But it shows if its 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')

关于ruby-on-rails - Ruby on Rails : if current page? 是主页,不显示表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31817051/

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