Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: if current page? is homepage, don't show form

I want to not show a form, but only if current page is NOT the home page

This is what I have so far...

I have my route setup:

root 'projects#index'

My view:

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

This doesn't show if the url is localhost:3000/projects

But it shows if its localhost:3000

So I need to somehow make sure that if its the homepage, it won't show. Also, I have search parameters for the home page, and I still don't want to show if its like localhost:3000/projects?search=blahblahblah

like image 618
hellomello Avatar asked Aug 04 '15 18:08

hellomello


1 Answers

Use the root_path helper:

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

or:

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

Also, according the documentation, no need url_for method:

current_page?(controller: 'projects', action: 'index')
like image 82
Philidor Avatar answered Sep 27 '22 21:09

Philidor