Files
grecia/app/models/poll/ballot.rb
Javi Martín 234a5108a4 Use strings for class_name
As mentioned in the Rails console:

DEPRECATION WARNING: Passing a class to the `class_name` is deprecated
and will raise an ArgumentError in Rails 5.2. It eagerloads more classes
than necessary and potentially creates circular dependencies. Please
pass the class name as a string.
2019-05-28 14:26:18 +02:00

37 lines
773 B
Ruby

class Poll::Ballot < ApplicationRecord
belongs_to :ballot_sheet, class_name: "Poll::BallotSheet"
validates :ballot_sheet_id, presence: true
def verify
investments.each do |investment_id|
add_investment(investment_id)
end
end
def add_investment(investment_id)
investment = find_investment(investment_id)
if investment.present? && not_already_added?(investment)
ballot.add_investment(investment)
end
end
def investments
data.split(",")
end
def ballot
Budget::Ballot.where(poll_ballot: self).first
end
def find_investment(investment_id)
ballot.budget.investments.where(id: investment_id).first
end
def not_already_added?(investment)
ballot.lines.where(investment: investment).blank?
end
end