Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 documen...
What is hash in rails?
As well as array, hash is an object to manage multiple objects.
Example : hash1 = { “Andy” => 28, “...
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...
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 ...
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 sing...
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
*Tw...
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...
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).li...
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 ch...
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...
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 ...
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 = {
t...
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 singula...
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)...
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 ...
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 uppercas...
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
Upcoming SlideShare
Loading in …5
×
Upcoming SlideShare
バカでもわかるRails #05
Next
Download to read offline and view in fullscreen.

Share

Rails for idiots #01 FlashCards for hash and CRUD

Download to read offline

Ruby on Rails, especially Rails is always difficult to understand for beginners. I made enjoyable quiz flashcards for beginners. You can repeat quiz by yourself like leaning foreign languages.

Related Books

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Rails for idiots #01 FlashCards for hash and CRUD

  1. 1. Rails for Idiots #01 hash and CRUD flashcards Daisuke Ishii - CEO of www.jenio.co Twitter@ishiid, email: dai@jenio.co 1
  2. 2. Let’s play like flashcards 2
  3. 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. 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. 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. 6. Q1: Please pick 3rd tweet and pass it to “t”. 6
  7. 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. 8. Q2: Now, display its id. 8
  9. 9. Q2: Now, display its id. 9 A: puts t[:id] => 3 or puts t.id => 3
  10. 10. Q3: Now, display its text. 10
  11. 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
  12. 12. Let’s learn about CRUD 12
  13. 13. Q4: What is CRUD? 13
  14. 14. Q4: What is CRUD? A: Create, Read, Update and Delete. It is a basic functions of computer software. 14
  15. 15. Let’s learn about CREATE 15
  16. 16. Q5: Create new tweet saying ‘It is sunny’. 16
  17. 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. 18. Q6: Give me recipe of CREATE 18
  19. 19. Q6: Give me recipe of CREATE A: t = TableName.new t.key = value t.save 19
  20. 20. Q7: Create Andy’s new tweet saying “See ya!” 20
  21. 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. 22. Q8: Give me recipe of CREATE hash 22
  23. 23. Q8: Give me recipe of CREATE hash A: t=TableName.new(hash) t.save *TableName needs to be singular and uppercase 23
  24. 24. Q9: Create Andy’s new tweet saying “See ya!” with create method 24
  25. 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. 26. Q10: Give me recipe of CREATE hash with create method 26
  27. 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
  28. 28. Let’s learn about READ 28
  29. 29. Q11: Find second tweet in database table 29
  30. 30. Q11: Find second tweet in database table A: Tweet.find(2) *Tweet needs to be singular and uppercase 30
  31. 31. Q12: Find second, third, fourth tweets in database table 31
  32. 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. 33. Q13: Find first tweet in database table 33
  34. 34. Q13: Find first tweet in database table A: Tweet.first *Tweet needs to be singular and uppercase 34
  35. 35. Q14: Find last tweet in database table 35
  36. 36. Q14: Find last tweet in database table A: Tweet.last *Tweet needs to be singular and uppercase 36
  37. 37. Q15: Find all tweets in database table 37
  38. 38. Q15: Find all tweets in database table A: Tweet.all *Tweet needs to be singular and uppercase 38
  39. 39. Q16: Find total number of tweets 39
  40. 40. Q16: Find total number of tweets A: Tweet.count *Tweet needs to be singular and uppercase 40
  41. 41. Q17: Find all tweets ordered by users 41
  42. 42. Q17: Find all tweets ordered by users A: Tweet.order(:user) *Tweet needs to be singular and uppercase 42
  43. 43. Q18: Find the first 10 tweets 43
  44. 44. Q18: Find the first 10 tweets A: Tweet.limit(10) *Tweet needs to be singular and uppercase 44
  45. 45. Q19: Find all tweets from user named “Bob” 45
  46. 46. Q19: Find all tweets from user named “Bob” A: Tweet.where(user:”Bob”) *Tweet needs to be singular and uppercase 46
  47. 47. Q20: Find only tweets from user named “Bob” ordered by text, only the first 10. 47
  48. 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. 49. Q21: Find only tweets from user named “Bob” just the first one. 49
  50. 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
  51. 51. Let’s learn about UPDATE 51
  52. 52. Q22: Find 3rd tweet and pass it to t. Update its user as “Andy”. 52
  53. 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. 54. Q23: Give me a recipe of previous codes. 54
  55. 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. 56. Q24: Find 2nd tweet and pass it to t. Update its text as “Hello” and user as “Andy”. 56
  57. 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. 58. Q25: Give me a recipe of previous codes. 58
  59. 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. 60. Q26: Find 2nd tweet and pass it to t. Update its text as “Hello” and user as “Andy”. Use update method. 60
  61. 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. 62. Q27: Give me a recipe of previous codes. 62
  63. 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
  64. 64. Let’s learn about DELETE 64
  65. 65. Q28: Find 3rd tweet and pass it to t. And delete it. 65
  66. 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. 67. Q29: Give me a recipe of previous codes. 67
  68. 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. 69. Q30: Find 3rd tweet and delete it in one line. 69
  70. 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. 71. Q31: Give me a recipe of previous codes. 71
  72. 72. Q31: Give me a recipe of previous codes. A: t=TableName.find(id). destroy *TableName needs to be singular and uppercase 72
  73. 73. Q32: Find all tweets and delete them in one line. 73
  74. 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. 75. Q33: Give me a recipe of previous codes. 75
  76. 76. Q33: Give me a recipe of previous codes. A: t=TableName.destroy_all *TableName needs to be singular and uppercase 76
  77. 77. Finish!!! Good Job!!! Let’s keep learning. 77 Follow me@Twitter & give me feedback! https://twitter.com/ishiid

Ruby on Rails, especially Rails is always difficult to understand for beginners. I made enjoyable quiz flashcards for beginners. You can repeat quiz by yourself like leaning foreign languages.

Views

Total views

624

On Slideshare

0

From embeds

0

Number of embeds

23

Actions

Downloads

3

Shares

0

Comments

0

Likes

0

×