Created
January 9, 2013 10:10
-
-
Save anonymous/4492062 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
# 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