tab/app/models/client.rb

24 lines
564 B
Ruby
Raw Normal View History

2015-09-08 11:44:40 +02:00
# == Schema Information
#
# Table name: clients
#
# id :integer not null, primary key
# name :string not null
# key :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
2015-09-08 11:30:11 +02:00
class Client < ActiveRecord::Base
2017-01-23 16:59:04 +01:00
rolify
2015-09-09 12:49:24 +02:00
has_many :issued_transactions, as: :issuer, class_name: 'Transaction'
2015-09-08 14:26:04 +02:00
before_create :generate_key
validates :name, presence: true, uniqueness: true
2015-09-08 15:51:23 +02:00
2015-09-08 14:26:04 +02:00
private
def generate_key
self.key = SecureRandom.base64(16) unless self.key
end
2015-09-08 11:30:11 +02:00
end