Ruby on Rails:如果是当前页面?是主页,不显示表格

hel*_*llo 5 ruby ruby-on-rails

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

这就是我到目前为止......

我有我的路线设置:

root 'projects#index'
Run Code Online (Sandbox Code Playgroud)

我的看法:

<% if !current_page?(url_for(:controller => 'projects', :action => 'index')) %>
  show some stuff
<% end %>
Run Code Online (Sandbox Code Playgroud)

如果网址是,则不显示 localhost:3000/projects

但它表明它是否 localhost:3000

所以我需要以某种方式确保如果它的主页,它将不会显示.此外,我有主页的搜索参数,我仍然不想显示它是否喜欢localhost:3000/projects?search=blahblahblah

Зел*_*ный 20

使用root_path帮手:

<% unless current_page?(root_path) %>
  show some stuff
<% end %>
Run Code Online (Sandbox Code Playgroud)

这不显示网址是否是,localhost:3000/projects但它显示了它是否localhost:3000

要么:

<% unless current_page?('/') || current_page?('/projects') %>
   # '/' the same as root_path
   show some stuff
<% end %>
Run Code Online (Sandbox Code Playgroud)

另外,根据documentation,没有必要的url_for方法:

current_page?(controller: 'projects', action: 'index')
Run Code Online (Sandbox Code Playgroud)