Was that so, the user_signed_in? method

Introduction

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.

What is devise

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.

Usual flow

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.

user_signed_in? method

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.

Does user_signed_in? have no meaning?


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

Was that so, the user_signed_in? method
I was addicted to the roll method
[Java] The story that the expected array was not obtained by the String.split method.
About the method
Command that the registered information was not found
Output about the method # 2
About the length method
About the authenticate method.
About the map method
About the ancestors method
About the to_s method.
Solved the problem that all the data in the table was displayed
Note the StringUtils # containsAny method
What is the pluck method?
Output about the method Part 1
about the where method (rails)
Understand the helper method form_with
Consideration about the times method
[Ruby] Method that returns truth
The languages that influenced Rust
What is the initialize method?
Consider implementing a method that returns the difference between two Lists
About the matter that I was addicted to how to use hashmap
The operator that was born to be born, instanceof (Java) ~ How to use the instanceof operator ~
"RSpec doesn't work!" The cause was spring, so I investigated it.
I don't understand the devise_parameter_sanitizer method, so I'll output it here.
The story that ARM's processing performance of Open JDK was low