1

I have a user model with a column superuser:boolean. I also using a navigationbar where I want to to have three different views according to those conditions:

  • When someone is not signed in
  • When someone is signed in as a user
  • When someone is signed is as a user and the boolean value for superuser is true

    <% if (user_signed_in? && user.super_user?) %>
    
    <% elsif (user_signed_in?) %>
    
    <% else %>
    

I am getting the error: "undefined local variable or method `user'"

How can I check if the column super_user of an user is true or false?

1 Answer 1

2

1) It looks like you're using Devise gem (because of user_signed_in?). In this case it is a current_user helper you're looking for, not user.

2) You do not need ? in here current_user.super_user - column is called super_user, not super_user?.

<% if (user_signed_in? && current_user.super_user) %>

<% elsif (user_signed_in?) %>

<% else %>
Sign up to request clarification or add additional context in comments.

1 Comment

@trickydiddy no probs, don't forget to accept the answer if that did it for you (I know you can't yet for ~10 more mins) :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.