class Attendance < ActiveRecord::Base attr_accessible :score, :user_id default_scope :order => 'created_at desc' include ApplicationHelper # 超过1天即没有连续的签到则又从10个金币开始累加 def next_score if time_between_days(Time.now, self.created_at) > 1 50 else score = self.score.to_i < 50 ? 50 : self.score.to_i (score + 10) < 100 ? score + 10 : 100 end end end