You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/app/models/library.rb

50 lines
1.1 KiB

class Library < ActiveRecord::Base
include AASM
belongs_to :user
has_many :library_applies, dependent: :delete_all
has_many :attachments, as: :container
5 years ago
has_many :library_library_tags, dependent: :delete_all
has_many :library_tags, through: :library_library_tags
attr_accessible :title, :content
validates :title, presence: true
validates :content, presence: true
validates :uuid, presence: true, uniqueness: true
6 years ago
acts_as_attachable
aasm(:status) do
state :pending, initiali: true
state :processing
state :refused
state :published
event :submit do
transitions from: [:pending, :refused], to: :processing
end
event :refuse do
transitions from: :processing, to: :refused
end
event :publish do
transitions from: :processing, to: :published
end
end
def generate_uuid
uuid = Util.generate_time_uuid
while Library.exists?(uuid: uuid)
uuid = Util.generate_time_uuid
end
self.uuid = uuid
end
def increment_visited_count!
Library.connection.execute("update libraries set visited_count = COALESCE(visited_count, 0) + 1 where id = #{id}")
end
end