Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Created April 7, 2012 16:12
Show Gist options
  • Save MikeSilvis/2330028 to your computer and use it in GitHub Desktop.
Save MikeSilvis/2330028 to your computer and use it in GitHub Desktop.
Cart Products index_by
1.9.2p318 :119 > c.products.index_by(&:id)
#=>
{
3 => #<Product:0x007fbc222615c0> {
:id => 3,
:name => "Racecar",
:description => "VRRRRRRRRRMMMMMMM",
:price_in_cents => 2065,
:active => 1,
:inactive_date => nil,
:created_at => Sat, 07 Apr 2012 15:36:10 UTC +00:00,
:updated_at => Sat, 07 Apr 2012 15:36:10 UTC +00:00,
:avatar_file_name => nil,
:avatar_content_type => nil,
:avatar_file_size => nil,
:avatar_updated_at => nil
},
1 => #<Product:0x007fbc2225fe00> {
:id => 1,
:name => "Apple",
:description => "Yummy wormy apple",
:price_in_cents => 100,
:active => 1,
:inactive_date => nil,
:created_at => Sat, 07 Apr 2012 15:36:09 UTC +00:00,
:updated_at => Sat, 07 Apr 2012 15:36:09 UTC +00:00,
:avatar_file_name => nil,
:avatar_content_type => nil,
:avatar_file_size => nil,
:avatar_updated_at => nil
},
2 => #<Product:0x007fbc222603f0> {
:id => 2,
:name => "Bananas",
:description => "Why do gorillas always eat me?",
:price_in_cents => 275,
:active => 1,
:inactive_date => nil,
:created_at => Sat, 07 Apr 2012 15:36:10 UTC +00:00,
:updated_at => Sat, 07 Apr 2012 15:36:10 UTC +00:00,
:avatar_file_name => nil,
:avatar_content_type => nil,
:avatar_file_size => nil,
:avatar_updated_at => nil
}
}
@j3j3
Copy link

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment