marksim / commentator

Easy comments on any page in Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Commentator

Commentator is a Rails Engine for adding commenting to any page/model in your app.

Installation

Install the gem

gem install commentator

Or in your Gemfile

gem 'commentator'

Configuration

rake commentator # Installs the DB Migration
# in config/routes.rb
mount Commentator::Engine => "/commentator"
# in application.js 
//= require commentator/comments
# in application_controller.rb
def authorize_comment
  # you have access to @commentable
  true # Your logic here
end
# in config/initializer.rb
Commentator.configure do |config|
  # config.owner_class = "User"
  # config.current_commenter_method = :current_user
  config.authorize_method = :authorize_comment
end

Usage

# In any model
class MyModel < ActiveRecord::Base
  include Commentator::Model
end

my_model.comments
# in any view
# @my_model.class_name + @my_model.id is the key for which comments to look up
<%= comments_for(@my_model) %>

# Not working yet - for comments not tied to a model, but tied to a page
# :about_us is the key for which comments to look up
<%= comments_for(:about_us) %>

Examples

In Views

# No new comments or replies
= comments_for(@my_model, :read_only => true)

# Replies to existing comments only
= comments_for(@my_model, :replies_only => true)

# No Nested Comments
= comments_for(@my_model, :no_replies => true)

In code

# if Commentator::Model is included in the model, you get
my_model.comments

About

Easy comments on any page in Rails

License:MIT License


Languages

Language:Ruby 83.0%Language:CSS 7.7%Language:JavaScript 4.9%Language:CoffeeScript 4.4%