README.md in parole-0.1.3 vs README.md in parole-0.1.4

- old
+ new

@@ -3,15 +3,16 @@ <img src="http://i.imgur.com/QQlNfGL.png" alt="Parole" /> </a> <br /> Parole adds the ability to comment on ActiveRecord records. <br /><br /> - <a href="https://rubygems.org/gems/parole"><img src="https://badge.fury.io/rb/parole.png" /></a> - <a href="https://codeclimate.com/github/mirego/parole"><img src="https://codeclimate.com/github/mirego/parole.png" /></a> - <a href="https://travis-ci.org/mirego/parole"><img src="https://travis-ci.org/mirego/parole.png?branch=master" /></a> + <a href="https://rubygems.org/gems/parole"><img src="http://img.shields.io/gem/v/parole.svg" /></a> + <a href="https://codeclimate.com/github/mirego/parole"><img src="http://img.shields.io/codeclimate/github/mirego/parole.svg" /></a> + <a href="https://travis-ci.org/mirego/parole"><img src="http://img.shields.io/travis/mirego/parole.svg" /></a> </p> + --- ## Installation Add this line to your application's Gemfile: @@ -61,40 +62,48 @@ article.comments.count # => 1 ``` ### Cache counters -Whenever a comment is created or destroyed, Parole looks into the commentable record and check -if there’s a `<role>_comments_count` column and/or a `comments_count` column. If so, it updates -them so they reflect the total number of comments and the number of comments of this role for -the record. +Whenever a comment is created or destroyed, Parole looks into the commentable record and the commenter +record and check if there’s a `<role>_comments_count` column and/or a `comments_count` column. +If so, it updates them so they reflect the total number of comments and the number of comments +of this role for the record. -So let’s say the `Article` model has the following columns: `photos_comments_count`, `videos_comments_count` and `comments_count`. +_Note:_ The commenter model must implements a `has_many` relationship that fetch its comments. +So let’s say the `Article` model has the following columns: `photos_comments_count`, `videos_comments_count` and `comments_count`, +and the `User` model has the following column: `comments_count`. + ```ruby class Article < ActiveRecord::Base acts_as_commentable roles: [:photos, :videos] end +class User < ActiveRecord::Base + has_many :comments, -> { where(commenter_type: 'User') }, foreign_key: :commenter_id +end user = User.find(1) article = Article.find(1) article.photos_comments.create(commenter: user, comment: 'Hello world!') article.photos_comments_count # => 1 article.videos_comments_count # => 0 article.comments_count # => 1 +user.comments_count # => 1 article.videos_comments.create(commenter: user, comment: 'Hello world again!') article.photos_comments_count # => 1 article.videos_comments_count # => 1 article.comments_count # => 2 +user.comments_count # => 2 ``` ## License -`Parole` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/parole/blob/master/LICENSE.md) file. +`Parole` is © 2013-2015 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/parole/blob/master/LICENSE.md) file. ## About Mirego -Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City. +[Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org). -We also love [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community. +We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.