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