Sha256: 0810667a1a8847ddc9482b900cd1f11e0033ad1460ad8a560b95bef767563cdc

Contents?: true

Size: 577 Bytes

Versions: 2

Compression:

Stored size: 577 Bytes

Contents

class Gutentag::Tag < ActiveRecord::Base
  has_many :taggings, :class_name => 'Gutentag::Tagging',
    :dependent => :destroy

  attr_accessible :name if Rails.version.to_s < '4.0.0'

  validates :name, :presence => true, :uniqueness => {:case_sensitive => false}

  before_validation :normalise_name

  def self.find_by_name(name)
    where(:name => Gutentag::TagName.normalise(name)).first
  end

  def self.find_or_create(name)
    find_by_name(name) || create(:name => name)
  end

  private

  def normalise_name
    self.name = Gutentag::TagName.normalise name
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gutentag-0.3.0 app/models/gutentag/tag.rb
gutentag-0.2.2 app/models/gutentag/tag.rb