Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have many Users that Vote on Requirements
- Each user can vote on a requirement on more than one criteria.
- So I want to get a list of all of the votes in a criteria, in a two-d array like such. There are some places where there is no vote. In that case the value in the array is an empty string
- User 1 User 2 User 3
- Req 1 9 4 5
- Req 2 1 "" ""
- Req 3 "" 4 0
- I currently get the array using this method but it is very slow as there are thousands of votes.
- class Criteria < ActiveRecord::Base
- set_table_name "criteria"
- set_primary_key :criteria_id
- belongs_to :instance
- has_many :votes
- def build_vote_array
- vote_array = Array.new(instance.requirements.count){|req_i|
- Array.new(instance.project.stakeholders.count) {|stake_i|
- vote = self.votes.select{|v|
- v.requirement_id == instance.requirements[req_i].id &&
- v.user_id == instance.project.stakeholders[stake_i].id
- }[0]
- vote == nil ? "" : vote.value
- }
- }
- end
- end
Add Comment
Please, Sign In to add comment