impress/app/models/campaign.rb

23 lines
400 B
Ruby
Raw Normal View History

2014-09-11 15:40:37 -07:00
class Campaign < ActiveRecord::Base
attr_accessible :active, :goal, :progress
has_many :donations
def progress_percent
2014-09-11 15:47:42 -07:00
[(progress.to_f / goal) * 100, 100].min
2014-09-11 15:40:37 -07:00
end
def remaining
goal - progress
end
def complete?
progress >= goal
end
2014-09-11 15:40:37 -07:00
def self.current
self.where(active: true).first or
raise ActiveRecord::RecordNotFound.new("no current campaign")
end
end