def self.categories_with_count
    Category.find_by_sql("SELECT categories.name AS name, categories.slug AS slug, COUNT(categorizations.id) AS count FROM categories LEFT OUTER JOIN categorizations ON categories.id = categorizations.category_id GROUP BY categorizations.category_id, categories.name, categories.slug ORDER BY categories.name")
end

Ruby Refactoring SQL Query in Ru...

by Elhu, May 24, 2011 14:14, 5 refactorings, tagged with rails activerecord, rails3

Hi!

I'm trying to retrie...

55bb5ae89ab81b436969697f65b60533 Talk
def disease_search(query)
    treatment_results = Array.new
    symptom_results = Array.new
...

Ruby Messy Blocks

by https://www.google.com/accounts/o8/id?id=AItOawncqSogDKAQLilNnxoB32ZKr-9LXu8x3WA, April 06, 2011 02:50, 6 refactorings, tagged with array, rails activerecord, blocks

This is a really ugly metho...

55502f40dc8b7c769880b10874abc9d0 Talk
def disease_search(query)
    treatment_results = Array.new
    symptom_results = Array.new
...

Ruby Messy Blocks

by https://www.google.com/accounts/o8/id?id=AItOawncqSogDKAQLilNnxoB32ZKr-9LXu8x3WA, April 06, 2011 02:50, 4 refactorings, tagged with array, rails activerecord, blocks

This is a really ugly metho...

55502f40dc8b7c769880b10874abc9d0 Talk
# In helper

def show_row(label, attribute)
...

Ruby Infer column name from inst...

by Josh, March 11, 2010 20:18, 1 refactoring, tagged with models, rails activerecord

Assume you have a model, li...

37d67924a83f566ba8220348a3e9bedb Talk
# Associations
#
# User: has_many :sources, :as => :sourceable, :dependent => :destroy
...

Ruby Get child elements from a o...

by Chris, March 11, 2010 08:27, 2 refactorings, tagged with activerecord, model, rails activerecord, assoziations

For a object (e.g. user), I...

5d7c8b8f2de06c07b2bf0848d20ce71f Talk
@merged << @array1
@merged << @array2
@merged.flatten!
...

Ruby Merging two active record a...

by KJF, February 09, 2010 21:28, 2 refactorings, tagged with rails activerecord

I'm merging two active reco...

A529b78031f700ca2005bdbd1af5ee7b Talk
named_scope :with_description, :conditions => "description IS NOT NULL and trim(description) != ''"

Ruby Doing a 'blank?' in named_s...

by Jo, November 26, 2008 19:01, 1 refactoring, tagged with rails activerecord

Can you do a .blank? in a n...

8aed7215b394d7fb97357951c733fa18 Talk
class Car < ActiveRecord::Base
  belongs_to :model
  has_many :photos
...

Ruby DRY it up please

by SoreGums, October 26, 2008 06:41, 6 refactorings, tagged with rails activerecord

This is a model.
my method...

D07cb7e4c1749e027447bd3b250c302f Talk
def all_shops(products)
    ids = []
    products.collect { |product| product.shops }.flatten.reject { |s| if ids.include?(s.id); true; else; ids.push(s.id); false; end }
...

Ruby Squash a collection.

by Eric, July 05, 2008 23:50, 3 refactorings, tagged with rails activerecord

The goal is to return a lis...

Fd1dab0af492d22ae0dc51d120a7c236 Talk