Implement Event Ratings
This commit is contained in:
parent
5be1ad52ee
commit
20f4853487
67 changed files with 1298 additions and 378 deletions
20
lib/tasks/migrate_votes.rake
Normal file
20
lib/tasks/migrate_votes.rake
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
namespace :votes do
|
||||
desc 'Migrate old votes to new voting system'
|
||||
task migrate: :environment do
|
||||
ActiveRecord::Base.transaction do
|
||||
Conference.all.each do |conf|
|
||||
VotableField.create(title: 'Overall', conference_id: conf.id, for_admin: true, stars: conf.program.rating, votable_type: 'Event')
|
||||
Event.all.each do |event|
|
||||
votes = Vote.where(event_id: event.id)
|
||||
break unless votes.present?
|
||||
avg_votes = votes.pluck(:rating).sum / votes.count
|
||||
votes.each do |vote|
|
||||
Rate.create(dimension: 'Overall', rater_id: vote.user_id, rateable_type: 'Event', stars: vote.rating, rateable_id: event.id )
|
||||
end
|
||||
RatingCache.create(cacheable_id: event.id, cacheable_type: 'Event', avg: avg_votes, qty: votes.count, dimension: 'Overall')
|
||||
end
|
||||
end
|
||||
end
|
||||
puts 'All done!'
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue