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

  • 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 is maintained and funded by Chef Surfing: "Find and hire great cooking talent in your city for a catered event, cooking class or weekly meal."