I will post the process of advancing the rails tutorial on my own.
It touches on words that I didn't understand in the process, jammed errors, and so on.
Please point out any mistakes as it is an output of personal learning.
Since this is my first post, I think there are many places that are difficult to read, but please forgive me.
Existence verification seems to be done with: presence. The tutorial often shows abbreviated code, so I'll follow you up until you understand it.
validates :name, presence: true
#If you put all parentheses
validates(:name, {presence: true}) #The column name to be verified is the first argument, and the content to be verified is the second argument.
a problem occured!! Running the test in Listing 6.13
RuntimeError: RuntimeError: database is locked
Is displayed and an error occurs.
What I tried to solve
Reference article 1 https://qiita.com/kambe0331/items/1eaf2383b39c721e7283 With reference to this article, I renamed the file test.sqlite3 under the db file and changed it back to the original name.
result It doesn't work ...
next
Reference article 2 https://stackoverflow.com/questions/7154664/ruby-sqlite3busyexception-database-is-locked/62730905#62730905 Refer to this article, quit DB Browser for SQlite, server, prompt, etc. once and start it again.
result I was able to clear the test.
Digression I was able to clear the test temporarily, but apparently I couldn't solve it fundamentally, and this error will continue to occur frequently.
The solution to the error is summarized in another article. https://qiita.com/shun_study_p/items/fbb4cb2d4c392063c9a9
It seems that length verification is done with: length.
validates :name, presence: true, length: { maximum: 50 }
#If you put parentheses for easy understanding
validates(:name, {presence: true, length: { maximum: 50 }})
As before, follow the parentheses yourself until you get used to it.
Uniqueness verification seems to be done with: uniqueness. It seems that you can specify whether it is case sensitive or not by using the option: case_sensitive.
case_sensitive: false
By doing so: I've added the option of making the value of uniqueness case-insensitive in verifying its uniqueness.
a problem occured!! The last time I ran the rails test
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
And an error has occurred. I got an error saying that I couldn't migrate when I executed the command that was displayed obediently ...
Solution Refer to the following article http://kzlog.picoaccel.com/post-995/
rails db:rollback RAILS_ENV=test
rails db:migrate RAILS_ENV=test
When I ran the above command, it worked fine.
This time I stumbled on a little error. However, I was able to understand the contents of Chapter 6.
Recommended Posts