Created
March 14, 2010 18:24
-
-
Save seanhandley/332130 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
# Offering from lee: | |
class NarrativeController | |
class << self | |
def next_collaberator_for(story) | |
raise ArgumentError "Require an instance of Story" unless story.is_a? Story | |
collab_ids = story.collabs.map(&:id) | |
last_collab_id = story.fics.collabs.last.collab_id | |
last_collab_index = collab_ids.index(last_collab_id) || -1 | |
next_collab_id = collab_ids[last_collab_index + 1] | |
Collab.find_by_id(next_collab_id) | |
end | |
end | |
end | |
# This works out who's the next collaborator to write a Fic on a given story. | |
# This would work well as an instance method on the Story Controller. | |
# Also, an Observer to watch for saves could use this after a Fic is saved in order to notify the next collaborator that it is their turn to write. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment