SlideShare a Scribd company logo
1 of 20
Download to read offline
Datatypes
RailsBridgeChicago Module 2
Ameeda Chowdhury
twitter.com/ameedahc
Dog table stores a dog’s name only
name is a field in the dogs table,
and it’s defined as of data type
string.
Because the name field is defined as
of data type string, this field can
only hold values that can be put in
quotes i.e. a dog can be anmed
“Hello world!” and “Frankie” and “57”,
but NOT 57 or :Frankie or 7.55
Dogs currently only have names…..
...but are missing important info...
color
age
fixed or not?
entrance date
Recall: Adding “name” to “dogs” table
When we first generated our "dogs" table, we put "name:string"
in our generating code – this created for us a field in our
"dogs" table called "name" that stores "string" values.
Let’s add “age” to “dogs” table
What data type should the age field be?
Possible data types for fields
:primary_key
:string
:text
:integer
:float
:decimal
:datetime
:time
:date
:binary
:boolean
An integer (as you may remember from math class) is any
number without a fractional part – e.g. 1, 0, 205, -53, etc.
A float, on the other hand, is any number that can have a
fractional part - e.g. 1.75, 0.5, 1.0
Commands to add “age”
Note: “age” NOT in the “dogs” table yet
Migrate the database to add “age”
Now “age” is a field of “dogs” table
STOP! You can’t update “age” yet ....
… Because “age” isn’t whitelisted in the
DogsController, only “name” is
/app/controllers/dogscontroller
.rb
Whitelist “age”
/app/controllers/dogscontroller
.rb
Add :age to the permit list
The form doesn’t have an “age” field
Add a number field to the form
/app/views/dogs/form
.html.erb
numberfield
is a Rails form helper; this creates a field that
accepts numbers in the form the user sees in their browser
http://api.rubyonrails.
org/classes/ActionView/Helpers/FormHelper.html
lists and explains the various form helpers available
in Rails
/app/views/dogs/form
.html.erb
Display each dog’s age
edit /app/views/dogs/index.html.erb
Commit changes!
Commit to git
Check out your app!
Make sure you can add and view dogs’ ages.
Congrats! Here’s what we’ve done...
1. added a field in the database to store the age
2. told the controller to accept the :age parameter
3. added a field in the form where we can enter the age
4. added a field in the index to display the age
Now, try it on your own...
Choose the right data type for each remaining field for the
dogs table and add them to the table.
1. the date a dog arrived in the shelter
2. the color of the dog
3. a description of the dog's temperament
4. whether or not the dog is fixed

More Related Content

Viewers also liked

Viewers also liked (12)

Manuela hernandez
Manuela hernandezManuela hernandez
Manuela hernandez
 
La necesidad de compañer, pdf
La necesidad de compañer, pdfLa necesidad de compañer, pdf
La necesidad de compañer, pdf
 
Sistema linear escalonamento
Sistema linear   escalonamentoSistema linear   escalonamento
Sistema linear escalonamento
 
Reliance Retirement fund
Reliance Retirement fundReliance Retirement fund
Reliance Retirement fund
 
Teraproc Application Cluster-as-a-Service Overview Presentation
Teraproc Application Cluster-as-a-Service Overview PresentationTeraproc Application Cluster-as-a-Service Overview Presentation
Teraproc Application Cluster-as-a-Service Overview Presentation
 
Hotel Overview small
Hotel Overview smallHotel Overview small
Hotel Overview small
 
Kebutuhan utama
Kebutuhan utamaKebutuhan utama
Kebutuhan utama
 
FOM Kommunikation: Das JOHARI-Fenster-Modell
FOM Kommunikation: Das JOHARI-Fenster-ModellFOM Kommunikation: Das JOHARI-Fenster-Modell
FOM Kommunikation: Das JOHARI-Fenster-Modell
 
GM-2
GM-2GM-2
GM-2
 
Unit 2
Unit 2Unit 2
Unit 2
 
4°basico a
4°basico a4°basico a
4°basico a
 
Roteiro de trabalho 3º ano - cineclube - versão editada sara
Roteiro de trabalho   3º ano - cineclube - versão editada saraRoteiro de trabalho   3º ano - cineclube - versão editada sara
Roteiro de trabalho 3º ano - cineclube - versão editada sara
 

Recently uploaded

Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

RBC Mod 2: Datatypes

  • 1. Datatypes RailsBridgeChicago Module 2 Ameeda Chowdhury twitter.com/ameedahc
  • 2. Dog table stores a dog’s name only name is a field in the dogs table, and it’s defined as of data type string. Because the name field is defined as of data type string, this field can only hold values that can be put in quotes i.e. a dog can be anmed “Hello world!” and “Frankie” and “57”, but NOT 57 or :Frankie or 7.55
  • 3. Dogs currently only have names…..
  • 4. ...but are missing important info... color age fixed or not? entrance date
  • 5. Recall: Adding “name” to “dogs” table When we first generated our "dogs" table, we put "name:string" in our generating code – this created for us a field in our "dogs" table called "name" that stores "string" values.
  • 6. Let’s add “age” to “dogs” table What data type should the age field be?
  • 7. Possible data types for fields :primary_key :string :text :integer :float :decimal :datetime :time :date :binary :boolean An integer (as you may remember from math class) is any number without a fractional part – e.g. 1, 0, 205, -53, etc. A float, on the other hand, is any number that can have a fractional part - e.g. 1.75, 0.5, 1.0
  • 8. Commands to add “age”
  • 9. Note: “age” NOT in the “dogs” table yet
  • 10. Migrate the database to add “age”
  • 11. Now “age” is a field of “dogs” table
  • 12. STOP! You can’t update “age” yet .... … Because “age” isn’t whitelisted in the DogsController, only “name” is /app/controllers/dogscontroller .rb
  • 14. The form doesn’t have an “age” field
  • 15. Add a number field to the form /app/views/dogs/form .html.erb numberfield is a Rails form helper; this creates a field that accepts numbers in the form the user sees in their browser http://api.rubyonrails. org/classes/ActionView/Helpers/FormHelper.html lists and explains the various form helpers available in Rails /app/views/dogs/form .html.erb
  • 16. Display each dog’s age edit /app/views/dogs/index.html.erb
  • 18. Check out your app! Make sure you can add and view dogs’ ages.
  • 19. Congrats! Here’s what we’ve done... 1. added a field in the database to store the age 2. told the controller to accept the :age parameter 3. added a field in the form where we can enter the age 4. added a field in the index to display the age
  • 20. Now, try it on your own... Choose the right data type for each remaining field for the dogs table and add them to the table. 1. the date a dog arrived in the shelter 2. the color of the dog 3. a description of the dog's temperament 4. whether or not the dog is fixed