- Add gem 'parrot' to your Gemfile
- Run rake parrot:install:migrations
- Run rake db:migrate
- Run rails g parrot MODEL_NAME
- Add subresources to routes
resources RESOURCE_NAME do resources :parrot_comments, controller: 'parrot/comments', path: 'comments' end
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).
- 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).
parrot was funded by Chef Surfing.