Sha256: 85c2297466b837defda6a87bfe349b4266c03580907fa6fe65501f2032299ad8

Contents?: true

Size: 397 Bytes

Versions: 5

Compression:

Stored size: 397 Bytes

Contents

class ArgumentTopic < ActiveRecord::Base
  has_many :arguments
  
  validates :name, presence: true, uniqueness: { case_sensitive: false }
  
  attr_accessible :name, :text
  
  def self.find_or_create_by_name(name)
    resource = where('LOWER(name) = ?', name.to_s.strip.downcase).first
    
    if resource
      resource
    else
      resource = create(name: name.to_s.strip)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
voluntary-0.7.1 app/models/argument_topic.rb
voluntary-0.7.0 app/models/argument_topic.rb
voluntary-0.6.0 app/models/argument_topic.rb
voluntary-0.5.2 app/models/argument_topic.rb
voluntary-0.5.1 app/models/argument_topic.rb