I am working on a ruby on rails application. For a session controller, I want to use a case to check if a user’s account is locked or banned. I am trying to use the object of a class as the case, and use when to check attributes.
For example,
user = Profile.find(1)
case user
when user.ban
redirect_to()
when user.lock
redirect_to()
else
redirect_to()
end
The only problem is that doesn’t work.
What does work is this:
case user.ban
when true
redirect_to()
else
redirect_to()
end
Any advice on how I can go about checking if a user object is banned or locked using a switch?
Thank you
Make a user.status method which returns a state of a user, then you can do this: