SlideShare a Scribd company logo
1 of 77
Download to read offline
Rails for Idiots #01
hash and CRUD flashcards
Daisuke Ishii - CEO of www.jenio.co
Twitter@ishiid, email: dai@jenio.co
1
Let’s play like flashcards
2
Let’s learn Rails in easy way
Rails is so difficult for beginners like me.
I always feel there should be very easy documentation explaining Rails.
I will try to explain the basics of Rails in a easy way.
My idea is to create simple flash cards like when we memorize foreign languages.
Please use the following Q&A with your friend, asking each other.
3
What is hash in rails?
As well as array, hash is an object to manage multiple objects.
Example : hash1 = { “Andy” => 28, “Bob” => 30, “Keith” => 32, ……..}
Key: Andy, Bob, Keith…
Value: 28, 30, 32….
variable = {key, value} hash1 = { “Andy”, 28 }
variable[:key] = value hash1[“Andy”] = 28
4
Let’s take an example of database table called “tweets”
This is like an excel sheet.
id text user
1 I’m fine today. Andy
2 I’ve got married! Bob
3 I’ve got new job. Keith
5
*Table name is always lowercase & plural like “tweets”.
Q1: Please pick 3rd tweet and pass it to “t”.
6
Q1: Please pick 3rd tweet and pass it to “t”.
7
A: t = Tweet.find(3)
*Tweet needs to be singular and uppercase.
Q2: Now, display its id.
8
Q2: Now, display its id.
9
A: puts t[:id] => 3
or puts t.id => 3
Q3: Now, display its text.
10
Q3: Now, display its text.
A: puts t[:text] => I’ve got
new job.
or puts t.text => I’ve got new
job.
11
Let’s learn about CRUD
12
Q4: What is CRUD?
13
Q4: What is CRUD?
A: Create, Read, Update and
Delete. It is a basic
functions of computer
software.
14
Let’s learn about
CREATE
15
Q5: Create new tweet saying ‘It is sunny’.
16
Q5: Create new tweet saying ‘It is sunny’.
A: t = Tweet.new
t.text = “It is sunny.”
t.save
*Tweet need to be singular and uppercase
17
Q6: Give me recipe of CREATE
18
Q6: Give me recipe of CREATE
A: t = TableName.new
t.key = value
t.save
19
Q7: Create Andy’s new tweet saying “See ya!”
20
Q7: Create Andy’s new tweet saying “See ya!”
A: t=Tweet.new( text: “See
ya!”, user: “Andy”)
t.save
*Tweet needs to be singular and uppercase
21
Q8: Give me recipe of CREATE hash
22
Q8: Give me recipe of CREATE hash
A: t=TableName.new(hash)
t.save
*TableName needs to be singular and uppercase
23
Q9: Create Andy’s new tweet saying “See ya!” with
create method
24
Q9: Create Andy’s new tweet saying “See ya!” with
create method
A: Tweet.create( text: “See
ya!”, user: “Andy”)
t.save
*Tweet needs to be singular and uppercase
25
Q10: Give me recipe of CREATE hash with create
method
26
Q10: Give me recipe of CREATE hash with create
method
A: TableName.create(hash)
t.save
*TableName needs to be singular and uppercase
27
Let’s learn about READ
28
Q11: Find second tweet in database table
29
Q11: Find second tweet in database table
A: Tweet.find(2)
*Tweet needs to be singular and uppercase
30
Q12: Find second, third, fourth tweets in database
table
31
Q12: Find second, third, fourth tweets in database
table
A: Tweet.find(3,4,5)
*Tweet needs to be singular and uppercase
32
Q13: Find first tweet in database table
33
Q13: Find first tweet in database table
A: Tweet.first
*Tweet needs to be singular and uppercase
34
Q14: Find last tweet in database table
35
Q14: Find last tweet in database table
A: Tweet.last
*Tweet needs to be singular and uppercase
36
Q15: Find all tweets in database table
37
Q15: Find all tweets in database table
A: Tweet.all
*Tweet needs to be singular and uppercase
38
Q16: Find total number of tweets
39
Q16: Find total number of tweets
A: Tweet.count
*Tweet needs to be singular and uppercase
40
Q17: Find all tweets ordered by users
41
Q17: Find all tweets ordered by users
A: Tweet.order(:user)
*Tweet needs to be singular and uppercase
42
Q18: Find the first 10 tweets
43
Q18: Find the first 10 tweets
A: Tweet.limit(10)
*Tweet needs to be singular and uppercase
44
Q19: Find all tweets from user named “Bob”
45
Q19: Find all tweets from user named “Bob”
A: Tweet.where(user:”Bob”)
*Tweet needs to be singular and uppercase
46
Q20: Find only tweets from user named “Bob”
ordered by text, only the first 10.
47
Q20: Find only tweets from user named “Bob”
ordered by text, only the first 10.
A:Tweet.where(user:”Bob”).
order(:text).limit(10)
*This is called method chaining
*Tweet needs to be singular and uppercase
48
Q21: Find only tweets from user named “Bob” just
the first one.
49
Q21: Find only tweets from user named “Bob” just
the first one.
A:Tweet.where(user:”Bob”).
first
*This is called method chaining
*Tweet needs to be singular and uppercase
50
Let’s learn about
UPDATE
51
Q22: Find 3rd tweet and pass it to t. Update its user
as “Andy”.
52
Q22: Find 3rd tweet and pass it to t. Update its user
as “Andy”.
A: t=Tweet.find(3)
t.user = “Andy”
t.save
*Tweet needs to be singular and uppercase 53
Q23: Give me a recipe of previous codes.
54
Q23: Give me a recipe of previous codes.
A: t=TableName.find(id)
t.key = value
t.save
*TableName needs to be singular and uppercase 55
Q24: Find 2nd tweet and pass it to t. Update its text
as “Hello” and user as “Andy”.
56
Q24: Find 2nd tweet and pass it to t. Update its text
as “Hello” and user as “Andy”.
A: t=Tweet.find(2)
t.attributes = {
text: “Hello”
user: “Andy” }
t.save
*Tweet needs to be singular and uppercase 57
Q25: Give me a recipe of previous codes.
58
Q25: Give me a recipe of previous codes.
A: t=TableName.find(id)
t.attributes = hash
t.save
*TableName needs to be singular and uppercase 59
Q26: Find 2nd tweet and pass it to t. Update its text
as “Hello” and user as “Andy”. Use update method.
60
Q26: Find 2nd tweet and pass it to t. Update its text
as “Hello” and user as “Andy”. Use update method.
A: t=Tweet.find(2)
t.update = {
text: “Hello”
user: “Andy” }
t.save
*Tweet needs to be singular and uppercase 61
Q27: Give me a recipe of previous codes.
62
Q27: Give me a recipe of previous codes.
A: t=TableName.find(id)
t = TableName.update(hash)
t.save
*TableName needs to be singular and uppercase 63
Let’s learn about
DELETE
64
Q28: Find 3rd tweet and pass it to t. And delete it.
65
Q28: Find 3rd tweet and pass it to t. And delete it.
A: t=Tweet.find(3)
t.destroy
*Tweet needs to be singular and uppercase
66
Q29: Give me a recipe of previous codes.
67
Q29: Give me a recipe of previous codes.
A: t=TableName.find(id)
t.destroy
*TableName needs to be singular and uppercase
68
Q30: Find 3rd tweet and delete it in one line.
69
Q30: Find 3rd tweet and delete it in one line.
A: t=Tweet.find(3).destroy
*Tweet needs to be singular and uppercase
70
Q31: Give me a recipe of previous codes.
71
Q31: Give me a recipe of previous codes.
A: t=TableName.find(id).
destroy
*TableName needs to be singular and uppercase
72
Q32: Find all tweets and delete them in one line.
73
Q32: Find all tweets and delete them in one line.
A: t=Tweet.destroy_all
*Tweet needs to be singular and uppercase
74
Q33: Give me a recipe of previous codes.
75
Q33: Give me a recipe of previous codes.
A: t=TableName.destroy_all
*TableName needs to be singular and uppercase
76
Finish!!! Good Job!!! Let’s keep learning.
77
Follow me@Twitter
& give me feedback!
https://twitter.com/ishiid

More Related Content

Recently uploaded

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Rails CRUD flashcards

  • 1. Rails for Idiots #01 hash and CRUD flashcards Daisuke Ishii - CEO of www.jenio.co Twitter@ishiid, email: dai@jenio.co 1
  • 2. Let’s play like flashcards 2
  • 3. Let’s learn Rails in easy way Rails is so difficult for beginners like me. I always feel there should be very easy documentation explaining Rails. I will try to explain the basics of Rails in a easy way. My idea is to create simple flash cards like when we memorize foreign languages. Please use the following Q&A with your friend, asking each other. 3
  • 4. What is hash in rails? As well as array, hash is an object to manage multiple objects. Example : hash1 = { “Andy” => 28, “Bob” => 30, “Keith” => 32, ……..} Key: Andy, Bob, Keith… Value: 28, 30, 32…. variable = {key, value} hash1 = { “Andy”, 28 } variable[:key] = value hash1[“Andy”] = 28 4
  • 5. Let’s take an example of database table called “tweets” This is like an excel sheet. id text user 1 I’m fine today. Andy 2 I’ve got married! Bob 3 I’ve got new job. Keith 5 *Table name is always lowercase & plural like “tweets”.
  • 6. Q1: Please pick 3rd tweet and pass it to “t”. 6
  • 7. Q1: Please pick 3rd tweet and pass it to “t”. 7 A: t = Tweet.find(3) *Tweet needs to be singular and uppercase.
  • 8. Q2: Now, display its id. 8
  • 9. Q2: Now, display its id. 9 A: puts t[:id] => 3 or puts t.id => 3
  • 10. Q3: Now, display its text. 10
  • 11. Q3: Now, display its text. A: puts t[:text] => I’ve got new job. or puts t.text => I’ve got new job. 11
  • 13. Q4: What is CRUD? 13
  • 14. Q4: What is CRUD? A: Create, Read, Update and Delete. It is a basic functions of computer software. 14
  • 16. Q5: Create new tweet saying ‘It is sunny’. 16
  • 17. Q5: Create new tweet saying ‘It is sunny’. A: t = Tweet.new t.text = “It is sunny.” t.save *Tweet need to be singular and uppercase 17
  • 18. Q6: Give me recipe of CREATE 18
  • 19. Q6: Give me recipe of CREATE A: t = TableName.new t.key = value t.save 19
  • 20. Q7: Create Andy’s new tweet saying “See ya!” 20
  • 21. Q7: Create Andy’s new tweet saying “See ya!” A: t=Tweet.new( text: “See ya!”, user: “Andy”) t.save *Tweet needs to be singular and uppercase 21
  • 22. Q8: Give me recipe of CREATE hash 22
  • 23. Q8: Give me recipe of CREATE hash A: t=TableName.new(hash) t.save *TableName needs to be singular and uppercase 23
  • 24. Q9: Create Andy’s new tweet saying “See ya!” with create method 24
  • 25. Q9: Create Andy’s new tweet saying “See ya!” with create method A: Tweet.create( text: “See ya!”, user: “Andy”) t.save *Tweet needs to be singular and uppercase 25
  • 26. Q10: Give me recipe of CREATE hash with create method 26
  • 27. Q10: Give me recipe of CREATE hash with create method A: TableName.create(hash) t.save *TableName needs to be singular and uppercase 27
  • 29. Q11: Find second tweet in database table 29
  • 30. Q11: Find second tweet in database table A: Tweet.find(2) *Tweet needs to be singular and uppercase 30
  • 31. Q12: Find second, third, fourth tweets in database table 31
  • 32. Q12: Find second, third, fourth tweets in database table A: Tweet.find(3,4,5) *Tweet needs to be singular and uppercase 32
  • 33. Q13: Find first tweet in database table 33
  • 34. Q13: Find first tweet in database table A: Tweet.first *Tweet needs to be singular and uppercase 34
  • 35. Q14: Find last tweet in database table 35
  • 36. Q14: Find last tweet in database table A: Tweet.last *Tweet needs to be singular and uppercase 36
  • 37. Q15: Find all tweets in database table 37
  • 38. Q15: Find all tweets in database table A: Tweet.all *Tweet needs to be singular and uppercase 38
  • 39. Q16: Find total number of tweets 39
  • 40. Q16: Find total number of tweets A: Tweet.count *Tweet needs to be singular and uppercase 40
  • 41. Q17: Find all tweets ordered by users 41
  • 42. Q17: Find all tweets ordered by users A: Tweet.order(:user) *Tweet needs to be singular and uppercase 42
  • 43. Q18: Find the first 10 tweets 43
  • 44. Q18: Find the first 10 tweets A: Tweet.limit(10) *Tweet needs to be singular and uppercase 44
  • 45. Q19: Find all tweets from user named “Bob” 45
  • 46. Q19: Find all tweets from user named “Bob” A: Tweet.where(user:”Bob”) *Tweet needs to be singular and uppercase 46
  • 47. Q20: Find only tweets from user named “Bob” ordered by text, only the first 10. 47
  • 48. Q20: Find only tweets from user named “Bob” ordered by text, only the first 10. A:Tweet.where(user:”Bob”). order(:text).limit(10) *This is called method chaining *Tweet needs to be singular and uppercase 48
  • 49. Q21: Find only tweets from user named “Bob” just the first one. 49
  • 50. Q21: Find only tweets from user named “Bob” just the first one. A:Tweet.where(user:”Bob”). first *This is called method chaining *Tweet needs to be singular and uppercase 50
  • 52. Q22: Find 3rd tweet and pass it to t. Update its user as “Andy”. 52
  • 53. Q22: Find 3rd tweet and pass it to t. Update its user as “Andy”. A: t=Tweet.find(3) t.user = “Andy” t.save *Tweet needs to be singular and uppercase 53
  • 54. Q23: Give me a recipe of previous codes. 54
  • 55. Q23: Give me a recipe of previous codes. A: t=TableName.find(id) t.key = value t.save *TableName needs to be singular and uppercase 55
  • 56. Q24: Find 2nd tweet and pass it to t. Update its text as “Hello” and user as “Andy”. 56
  • 57. Q24: Find 2nd tweet and pass it to t. Update its text as “Hello” and user as “Andy”. A: t=Tweet.find(2) t.attributes = { text: “Hello” user: “Andy” } t.save *Tweet needs to be singular and uppercase 57
  • 58. Q25: Give me a recipe of previous codes. 58
  • 59. Q25: Give me a recipe of previous codes. A: t=TableName.find(id) t.attributes = hash t.save *TableName needs to be singular and uppercase 59
  • 60. Q26: Find 2nd tweet and pass it to t. Update its text as “Hello” and user as “Andy”. Use update method. 60
  • 61. Q26: Find 2nd tweet and pass it to t. Update its text as “Hello” and user as “Andy”. Use update method. A: t=Tweet.find(2) t.update = { text: “Hello” user: “Andy” } t.save *Tweet needs to be singular and uppercase 61
  • 62. Q27: Give me a recipe of previous codes. 62
  • 63. Q27: Give me a recipe of previous codes. A: t=TableName.find(id) t = TableName.update(hash) t.save *TableName needs to be singular and uppercase 63
  • 65. Q28: Find 3rd tweet and pass it to t. And delete it. 65
  • 66. Q28: Find 3rd tweet and pass it to t. And delete it. A: t=Tweet.find(3) t.destroy *Tweet needs to be singular and uppercase 66
  • 67. Q29: Give me a recipe of previous codes. 67
  • 68. Q29: Give me a recipe of previous codes. A: t=TableName.find(id) t.destroy *TableName needs to be singular and uppercase 68
  • 69. Q30: Find 3rd tweet and delete it in one line. 69
  • 70. Q30: Find 3rd tweet and delete it in one line. A: t=Tweet.find(3).destroy *Tweet needs to be singular and uppercase 70
  • 71. Q31: Give me a recipe of previous codes. 71
  • 72. Q31: Give me a recipe of previous codes. A: t=TableName.find(id). destroy *TableName needs to be singular and uppercase 72
  • 73. Q32: Find all tweets and delete them in one line. 73
  • 74. Q32: Find all tweets and delete them in one line. A: t=Tweet.destroy_all *Tweet needs to be singular and uppercase 74
  • 75. Q33: Give me a recipe of previous codes. 75
  • 76. Q33: Give me a recipe of previous codes. A: t=TableName.destroy_all *TableName needs to be singular and uppercase 76
  • 77. Finish!!! Good Job!!! Let’s keep learning. 77 Follow me@Twitter & give me feedback! https://twitter.com/ishiid