In this project I cloned the popular blogging site tumblr.
The live version is up here
Some of the technologies featured include:
Posts can be of different types ie: Text, Quote, Photo.
All posts share some datafields ie: post_date, user_id
To avoid having to:
all_posts = current_user.text_posts
all_posts = all_posts.merge( current_user.photo_posts ).
the Post Model holds a field 'content_type' which is a string reference to the model name of the content the post holds. Thus to access a posts content I can use:
// in post.rb
def content
return false unless self.content_type
self.content_type.constantize.find_by_post_id(self.id)
end
None of the photos are held on heroku. Use the paperclip gem to store my photos in a bucket at AWS.
There are indeed many plugins to do rich text editng ( tinyMCE, nicEdit ...). After playing with both a little I discovered that the meat of what they do is centered around this command:
document.execCommand()
So I spent a day writing my own library for repeated use that fits my needs. Rome was not built in a day, while functional there are bugs listed in issues. And it works only in Chrome.
The content is scraped from popular real tumblr pages with the gem nokogiri.