CoC:Convention over Configuration Prioritize convention over configuration
Exit Rails console
View data
Article.count
Show all data
Article.all
Display specific data
Article.find(1)
Substitute specific data into a variable and retrieve the column
article = Article.find(1)
article.content
Update column
article = Article.find(1)
article.content = "hello world"
article.save
Show all data
articles = Aricle.all
articles.each {|article| p article}
-What is migration? Mechanism for creating / modifying database tables
Generate a migration file to add columns
rails generate migration AddCategoryToArticle category:string
Reflect database settings
rails db:migrate
Cancel database settings
rails db:rollback
Post a new article in the Rails console
article = Article.new article.feeling = "(^o^)" article.save
Recommended Posts