In Chapter 9 of the Rails tutorial, when creating a Remember Me function for implementing login function, there is "Automatically handle password column as a virtual attribute...", and "For that, use attr_accessor, Implement the user.remember_token method so that it can be used...", and the following code is described, but I do not understand why it becomes such code.
attr_accessor :remember_token
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end
○ Unclear point.
・Why is there a virtual attribute to create a remember method?
・In the first place, what are virtual attributes?
○ What I tried to solve → I checked attr_accessor
(Interpreted to change the instance variable so that it can be operated, but is it possible to create virtual attributes?)
I think this is a basic content, but I would appreciate it if you could teach me.
We apologize for the inconvenience, but we would appreciate your favor.
-
Answer # 1
Related articles
- ruby - i want to transition from create to show with rails
- ruby on rails - i don't understand the description of the form object pattern
- ruby - [rails] i want to create a link including the data attribute with the link_to helper
- ruby on rails 5 - i don't understand the difference between model and controller methods
- ruby on rails - i don't understand template is missing
- ruby on rails - unable to create controller
- ruby on rails 5 - rails: create an administrator screen using activeadmin colors of other pages change
- ruby on rails - create a chat feature with action cable on ec2 on rails aws
- ruby - unable to create rails model (environment: cloud9)
- ruby on rails 5 - rails: i want to create a timetable app
- ruby on rails - i want to be able to understand the group administrator
- ruby - i can't create a custom account with rails stripe
- ruby on rails - when calling the create action, the name attribute changes depending on whether it is indexhtmlerb or newhtmlerb
- ruby on rails - i'm trying to create a container in docker but it doesn't work i want to create a container
- ruby on rails - i get an error with rails db: create
- ruby on rails - not saved by create action
- ruby on rails - i don't understand the content of the error
- ruby - i can't "rails db: create rails_env = production" on aws
- ruby on rails - i want to create an image posting function with react (typescript), formik, rails api, activestorage
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
I haven't seen the tutorial
"There is a place to enter the password on the Remember Me screen."
I will write on the assumption that it will be.
There is no password item in the users table of the database, and it is designed to put the encrypted password in _password and _password somehow. In order to enter it encrypted, there is a mechanism behind it so that if you put a password in user.password and save it, it will be OK.
For this reason, it is necessary to have a mechanism to set password for user,
about it. It doesn't matter if it's virtual (not in the database) or real (for the trick).
So, attr_accessor, the attribute is the same (like) mechanism, so that the program can access various attributes such as email with user.email or user.email= (by defining methos of). , No change for ruby program
Oops, omission
When params.permit(:password) is used, an error will occur if there is no password= method. Therefore, temporary attribute definition is required.