gitlink-forgeplus/app/models/page.rb

50 lines
1.2 KiB
Ruby

# == Schema Information
#
# Table name: pages
#
# id :integer not null, primary key
# user_id :integer not null
# project_id :integer not null
# identifier :string(255)
# site_name :string(255)
# language_frame :integer default("0")
# theme :string(255)
# last_build_at :datetime
# state :boolean default("1")
# state_description :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_pages_on_project_id (project_id)
# index_pages_on_user_id (user_id)
#
class Page < ApplicationRecord
belongs_to :user
belongs_to :project
# language_frame 前端语言框架
enum language_frame: { hugo: 0, jeklly: 1, hexo: 2}
after_create do
PageService.genernate_user(user_id)
end
before_save do
if state_changed? && state == false
PageService.close_site(user_id, identifier)
end
end
def deploy_page(branch)
PageService.deploy_page(branch,self.id)
end
def url
"http://#{user.login}.kingchan.cn/#{identifier}"
end
end