Class: Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tag.rb

Defined Under Namespace

Classes: MultipleTagsFound

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create(conditions = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/models/tag.rb', line 25

def self.find_or_create(conditions={})
	tags = find(:all, :conditions => conditions)
	case tags.length
		when 0 
			self.create!(conditions)
		when 1 
			tags[0]
		else raise MultipleTagsFound.new("Multiple tags found matching #{conditions.inspect}.")
	end
end

Instance Method Details

#before_saveObject



21
22
23
# File 'app/models/tag.rb', line 21

def before_save
	name.squish!
end