Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2013 10:10
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 anonymous/4492062 to your computer and use it in GitHub Desktop.
Save anonymous/4492062 to your computer and use it in GitHub Desktop.
# Add post to user's collection
#
def collect_post(post, collection_title = 'Favourites')
# Check if collection exists
collection = self.collections.limit(1).where(:title => collection_title)
# if there is no such collection, create one!
if collection.length == 0
c = Collection.new
c.user = self
c.title = collection_title
c.save
end
# Assign post to collection
c = (c) ? c : collection
c.posts << post
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment