Ruby’s array class has a method #sample() good for randomizing array output values. [user_1, user_2, user_3, user_4].sample #=> user_3   [user_1, user_2, user_3, user_4].sample #=> user_1 It also takes a parameter of an integer. This works especially well when grabbing random data collections for sidebars or suggested reading. # expensive call to get 10 or 20 records [user_1, user_2, user_3, user_4, user_5 …].sample(3) #=> [user_5, user_3, user_1] Now on the front end if a user selects a user we can remove it from the collection without hitting the api again filling the gap with a new user. Consider the Facebook suggested friend or ad sidebar sections. :)

Postgres has many functions available for use. In this example we will look at how to utilize one of these functions in ActiveRecord. This formula will return the age not the date of post. The method age() is now added to the Post model. posts = Post.select(’*, age(created_at)) posts.each { |f| puts f.age } :)

In ActiveRecord we can get the first row of a table that is not part of some related criteria. In this example we are going to retrieve the next course where a student has yet to receive a grade. If we were to omit the .first(), we could get all the courses. This query operates on the assumption we have a method .get_grades() which takes a parameter of the model and returns all the grades for that model. The model diagram looks like this: Student – has_many -> Grades – belong_to -> Courses Course.where(‘id not in (?)’, Student.find(3245).get_grades(Course).map(&:id)).first :)