Skip to content
/ parrot Public

Simple commenting Rails Engine. Adds commentable behavior to any model easily.

Notifications You must be signed in to change notification settings

tute/parrot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parrot Gem: Simple commenting solution for Rails 3 apps.

Installation

  1. Add gem 'parrot' to your Gemfile
  2. Run rake parrot:install:migrations
  3. Run rake db:migrate
  4. Run rails g parrot MODEL_NAME
  5. Add subresources to routes
    resources RESOURCE_NAME do
      resources :parrot_comments, controller: 'parrot/comments', path: 'comments'
    end
    

Notes

Given @comment = Parrot::Comment.find(id):

  • rails g parrot MODEL_NAME (4th step of the installation) adds a parrot_comments class method in the model. It sets a polymorphic relation with Parrot::Comment, whose name is commentable. You can call @post.comments to get related comments, or @comment.commentable to get the related entry of a given comment.
  • The default "author" model is User. You may change it from config/initializers/parrot.rb. You can call @comment.author to get comment's author.
  • User model: has_many :comments, class_name: Parrot::Comment, foreign_key: :author_id
  • Parrot views calls to_s method on the comment's author. You may want to alias it, or the "ugly" Ruby object will be shown: alias_method :to_s, :name
  • You may define after_comment_path method on commentable model for defining where the user should be redirected after commenting (related resource by default).

To-do

  • A Parrot::Thread intermediate object between commentable entries and actual comments would abstract the FKs from the comments, would be the only tier between parrot subsystem and host app, and would make (un)subscriptions dead easy.
  • Not tested.
  • Show partial views examples for showing existing comments and comment form
  • Flash responders working?
  • Wiki: how to reopen parrot's subclasses from parent applications? (to_prepare).

Chef Surfing

parrot was funded by Chef Surfing.

About

Simple commenting Rails Engine. Adds commentable behavior to any model easily.

Resources

Stars

Watchers

Forks

Packages

No packages published