Skip to main content

Condition if devise action view

Gems / Libraries • Asked by Jacob Hedengren
Hi everyone,

I am struggeling with finding out how to add a condition to hide my navbar partial if user is currently in one of the devise views. For example if user is currently in devise sessions new, I would like to hide my navbar partial. How would I accomplish this?

/ Jacob

I think it is:

<% if devise_controller? %>

Hey Jacob (hah),

The current controller and action are in the params. So in your view, you can do something like:

<% unless params[:controller] == "devise/sessions" && params[:action] == "new" %>
  <!-- show the menu -->
<% end %>

Chris just beat me to the post - so I'll just add that Chris' answer is much better if you just want it applied to all devise controllers - much more concise if you don't need to differentiate between actions.

Thank you so much Chris and Jacob! Problem solved! 

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.