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
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,7 +129,8 @@ This is possible because of our primary and foreign key relationship and because
129
129
If any of this is new or confusing information please review Week 2, or simply try going over this example, and calling `to_sql` on queries to better understand relationships.
130
130
131
131
132
-
Homework: You should have at least one user and one product in your database at this point and time, if you don't please start over from the beginning. You will now run a script that will generate many fake users and many fake products, the technical term for this is "seeding" the database with fake data. We are using a gem called 'ffaker' but you don't need to know that. In the terminal (not the rails console) run this command:
132
+
#### Homework:
133
+
You should have at least one user and one product in your database at this point and time, if you don't please start over from the beginning. You will now run a script that will generate many fake users and many fake products, the technical term for this is "seeding" the database with fake data. We are using a gem called 'ffaker' but you don't need to know that. In the terminal (not the rails console) run this command:
133
134
134
135
$ rake fake:data
135
136
@@ -144,9 +145,9 @@ Go back into your rails console and do a count on users and products, you should
144
145
$ rails console
145
146
Loading development environment (Rails 3.2.6)
146
147
> User.count
147
-
=> 10000
148
+
=> 101 # your number might be different
148
149
> Product.count
149
-
=> 10000
150
+
=> 254 # your number might be different
150
151
151
152
Your numbers might be different but it should be more than 1.
152
153
@@ -158,9 +159,8 @@ Add this to the top of the `index.html.erb` file:
158
159
159
160
<h2>Hello World</h2>
160
161
161
-
When you refresh your page you should see something like:
162
+
When you refresh your page you should see the new text:
@@ -192,7 +192,7 @@ All together the log looks like this:
192
192
193
193
There is alot of information in a tiny package. When things go wrong in your app you can use the log output to verify your assumptions are correct, and to get error messages.
194
194
195
-
Homework:
195
+
#### Homework:
196
196
197
197
Visit a [localhost:3000/users](http://localhost:3000/users) and then find the log entry. Then open up the readme.md you coppied onto your local machine and fill out this information:
198
198
@@ -252,7 +252,9 @@ Since we have a relationship between our products and our user we can show the o
252
252
Check your logs again, did the SQL change? Are there any new statements, why?
253
253
254
254
255
-
Homework: We've pulled data out of our database and into our rails view, pretty sweet. But the product from `Product.first` isn't very interesting. Make a new ERB tag and in it make a different type of query, storing the value to a variable. `<%= product = Product.where(:name => 'rails book').first %>` or `<%= cheap_product = Product.where('price < 5').first %>`.
255
+
#### Homework:
256
+
257
+
We've pulled data out of our database and into our rails view, pretty sweet. But the product from `Product.first` isn't very interesting. Make a new ERB tag and in it make a different type of query, storing the value to a variable. `<%= product = Product.where(:name => 'rails book').first %>` or `<%= cheap_product = Product.where('price < 5').first %>`.
256
258
257
259
Then output the name of the product, it's price and the name of the owner of the product. After each take a look a the log and see if there are new SQL statements listed.
258
260
@@ -366,7 +368,7 @@ You can also see that our database was a little smarter, instead of n+1 queries
366
368
367
369
You don't always want to use `includes()` when using active record, but it is one tool in your toolbox for getting a faster page load, just check the logs for the tell tell sign of an n+1 problem if you see a ton of SQL queries getting spammed on each and every page refresh. Using `includes()` when you don't have this problem will actually slow down your page.
0 commit comments