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/career.rb

30 lines
628 B

class Career < ActiveRecord::Base
# attr_accessible :title, :body
has_many :career_faqs, :dependent => :destroy
has_many :career_stages, :dependent => :destroy, :order => "career_stages.position ASC"
acts_as_attachable
scope :published, lambda{where(status: true)}
# 章节数
def subject_count
count = 0
self.career_stages.each do |stage|
count += stage.subjects.count
end
count
end
# 实训数
def shixun_count
count = 0
self.career_stages.each do |stage|
stage.subjects.each do |subject|
count += subject.shixuns.count
end
end
count
end
end