SlideShare una empresa de Scribd logo
1 de 77
Descargar para leer sin conexión
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

Más contenido relacionado

Último

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Destacado

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
 

Destacado (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 for idiots #01 FlashCards for hash and CRUD

  • 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