Code Monkey home page Code Monkey logo

the_comments's Introduction

This Repo under development!

TheComments

Gem Version | Build Status | Code Climate | (rubygems)

TheComments - probably, best commenting system for Rails

Main features

  • Threaded comments
  • Useful cache counters
  • Admin UI for moderation
  • Online Support via skype: ilya.killich
  • Denormalization for Recent comments
  • Production-ready commenting system for Rails 4+
  • Designed for preprocessors Sanitize, Textile, Markdawn etc.

Quick Start Installation

1. Gems install

Gemfile

gem 'the_comments', "~> 2.0"

gem 'haml'                # or gem 'slim'
gem 'awesome_nested_set'  # or same gem

Bundle

bundle

2. Migrations install

Copy migrations

rake the_comments_engine:install:migrations

Will create:

  • xxxxx_change_user.rb
  • xxxxx_create_comments.rb
  • xxxxx_change_commentable.rb

⚠️   Open and change xxxxx_change_commentable.rb migration

class ChangeCommentable < ActiveRecord::Migration
  def change
    # Additional fields to Commentable Models
    # [:posts, :articles, ... ]

    # There is only Post model is commentable
    [:posts].each do |table_name|
      change_table table_name do |t|
        t.integer :draft_comments_count,     default: 0
        t.integer :published_comments_count, default: 0
        t.integer :deleted_comments_count,   default: 0
      end
    end
  end
end

Invoke migrations

rake db:migrate

3. Code install

rails g the_comments install

Will create:

  • config/initializers/the_comments.rb
  • app/controllers/comments_controller.rb
  • app/models/comment.rb

⚠️   Open each file and follow an instructions

4. Models modifictions

app/models/user.rb

class User < ActiveRecord::Base
  include TheComments::User

  has_many :posts

  def admin?
    self == User.first
  end

  def comments_admin?
    admin?
  end

  def comments_moderator? comment
    id == comment.holder_id
  end
end

app/models/post.rb

class Post < ActiveRecord::Base
  include TheComments::Commentable

  belongs_to :user

  # Denormalization methods
  # Please, read about advanced using
  def commentable_title
    "Undefined Post Title"
  end

  def commentable_url
    "#"
  end

  def commentable_state
    "published"
  end
end

5. Assets install

app/assets/stylesheets/application.css

/*
 *= require the_comments
*/

app/assets/javascripts/application.js

//= require the_comments

6. Controller code example

app/controllers/posts_controllers.rb

def show
  @post     = Post.find params[:id]
  @comments = @post.comments.with_state([:draft, :published])
end

7. View code example

app/views/posts/show.html.haml

= render partial: 'the_comments/tree', locals: { commentable: @post, comments_tree: @comments }

MIT License

Copyright (c) 2013 Ilya N. Zykin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

the_comments's People

Contributors

the-teacher avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.