Files
grecia/app/models/spending_proposal.rb
2016-01-11 12:18:46 +01:00

33 lines
988 B
Ruby

class SpendingProposal < ActiveRecord::Base
include Measurable
include Sanitizable
apply_simple_captcha
RESOLUTIONS = ["accepted", "rejected"]
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :geozone
validates :title, presence: true
validates :author, presence: true
validates :description, presence: true
validates :title, length: { in: 4..SpendingProposal.title_max_length }
validates :description, length: { maximum: SpendingProposal.description_max_length }
validates :resolution, inclusion: { in: RESOLUTIONS, allow_nil: true }
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
scope :accepted, -> { where(resolution: "accepted") }
scope :rejected, -> { where(resolution: "rejected") }
scope :unresolved, -> { where(resolution: nil) }
def accept
update_attribute(:resolution, "accepted")
end
def reject
update_attribute(:resolution, "rejected")
end
end