class User
↑ This is the content of the user model with the verification content entered in the name column and email column.
I can understand the verification itself, but in the second line before_save {self.email = email.downcace}
I don't understand the reason to use self.
Is it a rule to use self as the type of the callback method? (Should it be considered as something?)
Is this defined as a class method?
If so, why put a class method?
As a result of the investigation,
○ self here refers to the user object at the time the method is called
○ Class method is the method to apply to the class
I think it's a rudimentary content, but I hope you can teach me and hold it.
We apologize for the inconvenience, but thank you.
-
Answer # 1
-
Answer # 2
The result of the examination is correct.
In such a case, self is not necessary in most cases, but if self is omitted (not only before_save), it may be mistaken for a "mere variable".
I think that's because I didn't like it, so I added self just in case.
Related articles
- ruby on rails 5 - ruby: i don't understand the meaning of the two inequality signs
- ruby on rails - i don't understand the description of the form object pattern
- ruby - unable to create rails model (environment: cloud9)
- ruby on rails - the link between the model created by devise and the model originally created does not work
- ruby - [rails] i want to find the date difference using the model created_at
- ruby on rails - i want to validate only the foreign key on the model side
- ruby on rails - returns a value from the rails model to the controller
- ruby on rails - i can't create a model with rails
- ruby on rails - product model test code does not succeed
- ruby - i don't understand the meaning of "redis:" described in yml file etc when dealing with redis in rails
- ruby on rails - i don't understand the content of the error
- ruby on rails - i don't understand template is missing
- ruby - pass the value from the controller in the rails model
- ruby on rails - i want to know the meaning of the dotted line of the er diagram created using the er diagram creation tool
- ruby on rails 5 - i don't understand the difference between model and controller methods
- [ruby on rails] how to write when getting a model nested in multiple stages with includes
- ruby on rails - i want to be able to understand the group administrator
- ruby on rails - rails associated model is not saved in db
- ruby on rails 5 - child model record not created
- [ruby] i don't understand the meaning of the error statement
- 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
before_save
The blocks inside areModel instanceIt runs in the context of. That is, thisself
Refers to the model instance.And
email =
If you substituteLocal variableSince the model will not be rewritten as it is assigned to, in order to call the setter of the modelself
Is required.