[RUBY] rails tutorial Chapter 6

Introduction

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.

Chapter 6 Creating a User Model

6.2.2 Verify existence

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

6.2.3 Verify length

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.

6.2.5 Verify uniqueness

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.

At the end

This time I stumbled on a little error. However, I was able to understand the contents of Chapter 6.

Recommended Posts

rails tutorial Chapter 6
rails tutorial Chapter 1
rails tutorial Chapter 7
rails tutorial Chapter 5
rails tutorial Chapter 10
rails tutorial Chapter 9
rails tutorial Chapter 8
Rails Tutorial Chapter 5 Notes
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
Rails Tutorial Chapter 3 Learning
Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial Chapter 4 Notes
Rails Tutorial Chapter 4 Learning
Rails Tutorial Chapter 1 Learning
Rails Tutorial Chapter 2 Learning
Rails Tutorial Chapter 8 Notes
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
rails tutorial
[Rails Tutorial Chapter 4] Rails-flavored Ruby
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
Rails tutorial test
[Rails Tutorial Chapter 5] Create a layout
rails tutorial chapter 10 summary (for self-learning)
Rails tutorial memorandum 1
Rails tutorial memorandum 2
Chewing Rails Tutorial [Chapter 2 Toy Application]
Start Rails Tutorial
[Beginner] Rails Tutorial
Rails Tutorial (4th Edition) Memo Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial 6th Edition Learning Summary Chapter 7
Rails Tutorial 6th Edition Learning Summary Chapter 4
Rails Tutorial 6th Edition Learning Summary Chapter 9
Rails Tutorial 6th Edition Learning Summary Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 5
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial Chapter 0: Preliminary Basic Knowledge Learning 5
Rails Tutorial 6th Edition Learning Summary Chapter 3
Rails Tutorial 6th Edition Learning Summary Chapter 8
Chapter 4 Rails Flavored Ruby
Rails Tutorial cheat sheet
[Rails] Learning with Rails tutorial
rails tutorial fighting notes Ⅲ
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 6
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 3
Rails Tutorial Chapter 1 From Zero to Deployment [Try]
Chewing Rails Tutorial [Chapter 3 Creating Almost Static Pages]
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
Resolve Gem :: FilePermissionError when running gem install rails (Rails Tutorial Chapter 1)
[Ruby on Rails Tutorial] Error in the test in Chapter 3
11.1 AccountActivations Resources: Rails Tutorial Notes-Chapter 11
Rails Tutorial Records and Memorandum # 0
I tried Rails beginner [Chapter 1]
Rails Tutorial (4th Edition) Summary