Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSteven Fried
Courses Plus Student 5,638 PointsQuestion about Active Record, Scopes, 1st Code Challenge
This course's presentation is so disorganized that I cannot figure out what the correct answer to the first code challenge on scopes is. I've gone back and watched each of the lessons at least a second time (some more than that) to no avail. Can someone please point me in the right direction?
4 Answers
jakecurreri
9,702 PointsIt is a tough course in regards to organization! But a wealth of information to be gained.
I cannot remember which "code script" is first, but here are two answers:
1. Command Line Take the starting query . . . sort the results by first_name field
Person.where(age: 31).order("first_name DESC")
Where and order are SQL-reference methods (if you've taken the database course) when referenced from the command line. In scopes, he talks a lot about name scopes, but ultimately those mean nothing if you're not comfortable with SQL syntax.
2. Regular Scopes Build a finder scope called hamptons
class Person < ActiveRecord::Base
scope :hamptons, -> { where(first_name: "Hampton")}
end
This one is a bit tricky since (at this point) you haven't used specific name scopes in the course, but only argument-based scopes. Simply put, within a class, you revert to Ruby syntax for SQL-reference methods.
Steven Fried
Courses Plus Student 5,638 PointsThanks. Those did it.
Emily Coltman
Courses Plus Student 9,623 PointsI'm stuck on the second question :( The example above didn't work for me unfortunately, and the system responses don't actually tell you what you're doing wrong! For example, the response needs to say "Put a colon here" or "Use curly braces instead of parentheses" and explain why. That's what's needed for total beginners :)
Emily Coltman
Courses Plus Student 9,623 PointsOK, passed - what was making it not work was an extra space :( Would have been so useful to have been specifically told that rather than getting a gobbledygook error message!