Skip to content

Instantly share code, notes, and snippets.

@seebq
Created September 28, 2011 16:29
Show Gist options
  • Save seebq/1248404 to your computer and use it in GitHub Desktop.
Save seebq/1248404 to your computer and use it in GitHub Desktop.
class Widget < ActiveRecord::Base
belongs_to :box
has_many :categorizations
has_many :categories, :through => :categorizations
# Returns a sentence of all the categories.
def category_names
if categories.empty?
"None"
else
categories.map {|c| c.name }.to_sentence
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment