Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dandorman/858958 to your computer and use it in GitHub Desktop.
Save dandorman/858958 to your computer and use it in GitHub Desktop.
pool = FeaturePool.find_by_name('discussions/primary')
position = 1
previous = pool.feature_appearances.all(:conditions => 'featured_at IS NOT NULL', :order => 'featured_at')
previous.each do |appearance|
appearance.update_attribute(:position, position)
position += 1
end
pool.update_attribute(:head, previous_and_current.last(pool.rotate_count).to_a.last.position + 1)
current_and_upcoming = pool.feature_appearances.all(:conditions => 'featured_at IS NULL', :order => 'created_at')
current_and_upcoming.first(pool.display_count).each { |appearance| appearance.update_attribute(:featured_at, Time.now.utc) }
current_and_upcoming.each do |appearance|
appearance.update_attribute(:position, position)
position += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment