Created
March 7, 2011 18:44
-
-
Save dandorman/858958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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