Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Created March 14, 2010 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanhandley/332130 to your computer and use it in GitHub Desktop.
Save seanhandley/332130 to your computer and use it in GitHub Desktop.
# 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