I've been thinking about it ever since I started learning programming. About the method name.
The problem of not knowing how much the method name is meaningful.
Since I can create the method myself, I can't judge how much it makes sense. This article introduces that I used to think that the user_signed_in? Method
had meaning to everything, but it didn't.
It is one of the gems that can be handled by Ruby, and it is a convenient gem that has a set of user management functions and can easily implement login functions.
When managing users using devise, generate models, controllers, and views in the terminal. Example)
rails g devise user
Yes, I always use user
as the model name and controller name.
A method to check if the user is signed in
If you are signed in, ture
If you are logged out, false
Will be returned.
Therefore, it is often used together with the if statement to branch what is displayed by the signed-in user and the non-signed user.
rails g devise admin
I created user and admin models and controllers with devise. So, I was worried about what to do when I wanted to display it only to admin.
The user
part of user_signed_in? Can be changed! !!
admin_signed_in?
did not result in an error.
Recommended Posts