I wrote a method to encrypt the password using BCrypt and assign it to the password in User's model file.
After that, I created a seed file and put it in, but when I tried to get the encrypted password, it didn't work.
Rather, I can get it, but I don't understand why I can get it with such a description. I would like somebody to teach.
The column name for User password is
It is described as.
class User</pre> <p><code>seed.rb</code></p> <pre><code data-language = "Ruby">User.create! ( password: "hogehoge" )
And after inputting db: seed, at the terminal
rails r "puts User.first.hashed_password"
Then the encrypted password will be output.
At this time, why should the password of seed.rb be described as password instead of hashed_password?
First in seed.rb
Was described. In this case, the output to the terminal will be the hogehoge before it is encrypted.
When creating the table, I used hashed_password for the password column, so I thought I had to use the same hashed_password for seed.rb. What's wrong?
I would be grateful if anyone could tell me. Thank you.
Answer # 1
I think you wrote has_secure_password in model.
As a result, the process of "encrypting the password before saving and putting it in hashed_password" will be performed.
I haven't read the code, so it's probably from the behavior.
I think I'm defining a before_save hook.
- ruby on rails - i'm having trouble getting an actionview :: syntaxerror while implementing category selection using active_hash
- ruby - i'm having trouble getting data out across tables
- ruby - i'm having trouble setting environment variables for activeadmin: access denied for user'root' @'localhost' (using passwo
- i'm having trouble with ruby's word bingo algorithm
- ruby - i am having trouble saving the data of collection_check_boxes to the table
- ruby on rails - i'm having trouble installing rails
- ruby - [rails] i'm having trouble saving a table with the create action
- ruby - i'm having trouble solving the missing required keys: [: id] error
- ruby - i'm having trouble with rails nomethoderror (i want to get data with each method!)
- i'm having trouble getting an error when using bind with python tkinter
- ruby - [i'm having trouble with an error] cannot add foreign key constraint
- ruby - [rails] i'm having trouble with permission denied @ dir_s_mkdir -
- mysql - i'm having trouble getting the name of the person who posted the message to appear in the view
- ruby on rails - i'm having trouble solving the test error
- ruby on rails - i'm having trouble downloading homebrew to my mac
- [ruby] i'm having trouble with nomethoderror
- i'm having trouble installing the python library from github
- vba - i'm having trouble with excel macros i want to copy the contents of a sheet and paste it as it is on a new sheet
- ruby - conditional branching is complicated and i am in trouble
- ruby - passing variables using render partial
- ruby - implementation of friendly forwarding
- ruby - i want to solve the n + 1 problem when using rails where method in loop processing
- ruby - [rails] form_with doesn't have proper name attribute
- ruby - rails cannot be started in the production environment when building an ec2 environment
- ruby - if you try to make the value of the array (json) sent on the vue side a strong parameter, a nomethoderror error will occu
- ruby - i want to display the edit button and delete button on the index page
- ruby - i want to generate a random password (mixed alphanumeric characters)
- ruby - sass :: syntaxerror on rails s
- ruby - i want to display new posts i made on the top page only for myself