You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,25 @@ Note directions that start with `$` indicate they are on the command line, you s
10
10
11
11
## Fork & Clone
12
12
13
+
Go to the directory where you like to store your rails code.
14
+
13
15
Fork this project and then clone it to your local machine.
14
16
15
17
18
+
## Ruby
19
+
20
+
You will need ruby 1.9 or higher for this example. You can check your version of Ruby by running:
21
+
22
+
$ ruby -v
23
+
16
24
## Install
17
25
18
26
Once on your local machine you will need to navigate to the project directory and run:
19
27
20
28
$ bundle install
29
+
30
+
This might take awhile, afterwards you will need to run:
31
+
21
32
$ rake db:create
22
33
$ rake db:migrate
23
34
@@ -36,7 +47,7 @@ This means that if you visit [localhost:3000/products](http://localhost:3000/pro
36
47
37
48
## 1) Populating Data
38
49
39
-
If you didn't already create a user by visiting [localhost:3000/users/new](http://localhost:3000/users/new) filling out the form and hitting submit.
50
+
If you didn't already, create a user by visiting [localhost:3000/users/new](http://localhost:3000/users/new) filling out the form and hitting submit.
40
51
41
52
In a new terminal run the rails console:
42
53
@@ -58,16 +69,22 @@ From here we can use our rails code and populate our database and perform querie
58
69
Now that you've got a user in your database lets make sure we can find them again with SQL. Take the name entered above (in this case `richard`) and search the database for it:
59
70
60
71
72
+
> User.first.name
73
+
=> 'richard'
61
74
> User.where(:name => 'richard')
62
75
=> [#<User id: 1, name: "richard", ... >]
63
76
64
77
Great that found ALL of the users named 'richard', if you got an empty array try again, make sure to use the name you used. If we wanted to find only one richard, we could limit the query and pull out the first user like this:
65
78
79
+
> User.first.name
80
+
=> 'richard'
66
81
> User.where(:name => 'richard').first
67
82
=> #<User id: 1, name: "richard", ... >
68
83
69
84
Cool, now we can store that user to a variable to use later:
70
85
86
+
> User.first.name
87
+
=> 'richard'
71
88
> rich = User.where(:name => 'richard').first
72
89
> rich.name
73
90
=> "richard"
@@ -82,7 +99,7 @@ If you look in the user model `apps/models/user.rb` you will see that users have
82
99
You will see that each product contains a foreign key called `user_id` lets add a product to our user. Using the existing variable from previously we can see all of our user's products:
0 commit comments