Skip to content

Instantly share code, notes, and snippets.

View JamesDullaghan's full-sized avatar
🎯
Focusing

James D JamesDullaghan

🎯
Focusing
View GitHub Profile
@JamesDullaghan
JamesDullaghan / ActiveRecord_Schneems_Arrays.mdown
Created April 26, 2013 03:10
ActiveRecord Schneems Arrays tutorial notes

#Arrays# ###Using the Docs###

[1,2,3,4].each {|x| puts x + 1 }
2
3
4
5
=> [1,2,3,4]

@JamesDullaghan
JamesDullaghan / ActiveRecord_Schneems_MIXMATCH.mdown
Created April 26, 2013 01:03
ActiveRecord Schneems Mixing and Matching Queries tutorial notes

#Mixing and Matching Queries#

puts Product.where(:price => 5).
             where(:name => "apple").
             order(:created_at).
             limit(55).
             joins(:users).
             where(:user => {:name => "richard"})

##Each method takes the output of the previous and adds to it##

@JamesDullaghan
JamesDullaghan / ActiveRecord_Schneems_grouping.mdown
Created April 25, 2013 22:30
ActiveRecord Schneems Grouping Tutorial Notes

#Grouping#

prods = Product.group(:price).count

Returns

puts prods
=> {573=>3, 574=>4, 575=>6, 576=>4}

The group method returns a hash of all prices, along with the count of each price. For example, there must be 3 items priced at 573