Ruby on Rails: if the current page? on the main page, don't show the form
I want not to show the form, but only if the current page is NOT the main page
This is what I have so far ...
I have a route setup:
root 'projects#index'
My opinion:
<% if !current_page?(url_for(:controller => 'projects', :action => 'index')) %>
show some stuff
<% end %>
It 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 homepage won't show. Also, I have search options for the home page and I still don't want to show if I like itlocalhost:3000/projects?search=blahblahblah
source to share
Use a helper root_path
:
<% unless current_page?(root_path) %>
show some stuff
<% end %>
It doesn't mean the url
localhost:3000/projects
But it shows if itslocalhost:3000
or
<% unless current_page?('/') || current_page?('/projects') %>
# '/' the same as root_path
show some stuff
<% end %>
Also, according to documentation
no need to use the method url_for
:
current_page?(controller: 'projects', action: 'index')
source to share