All threads / Condition if devise action view

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Condition if devise action view

Jacob Hedengren asked in Gems / Libraries
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! 
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.