Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Reputation system Rails engine.
Ruby JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Merit Gem: Reputation rules (badges, points and rankings) for Rails applications


Build Status


  1. Add gem 'merit' to your Gemfile
  2. Run rails g merit:install
  3. Run rails g merit MODEL_NAME
  4. Run rake db:migrate
  5. Configure reputation rules for your application

Defining badge rules

You may give badges to any resource on your application if some condition holds. Badges may have levels, and may be temporary. Define rules on app/models/merit_badge_rules.rb:

grant_on accepts:

  • 'controller#action' string (similar to Rails routes)
  • :badge for badge name
  • :level for badge level
  • :to method name over target_object which obtains object to badge
  • :model_name (string) define controller's name if it differs from the model (like RegistrationsController for User model).
  • :temporary (boolean) if the receiver had the badge but the condition doesn't hold anymore, remove it. false by default (badges are kept forever).
  • &block
    • empty (always grants)
    • a block which evaluates to boolean (recieves target object as parameter)
    • a block with a hash composed of methods to run on the target object with expected values


grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do
  { :votes => 5 }

grant_on ['users#create', 'users#update'], :badge => 'autobiographer', :temporary => true do |user| && user.address.present?

Defining point rules

Points are a simple integer value which are given to "meritable" resources. They are given on actions-triggered, either to the action user or to the method(s) defined in the :to option. Define rules on app/models/merit_point_rules.rb:


score 10, :on => [

score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]

score 20, :on => [

Defining rank rules

Rankings are very similar to badges. They give "badges" which have a hierarchy defined by level's lexicografical order (greater is better). If a rank is granted, lower level ranks are taken off. 5 stars is a common ranking use case.

They are not given at specified actions like badges, you should define a cron job to test if ranks are to be granted.

Define rules on app/models/merit_rank_rules.rb:

set_rank accepts:

  • badge_name name of this ranking
  • :level ranking level (greater is better)
  • :to model or scope to check if new rankings apply

Check for rules on a rake task executed in background like:

task :cron => :environment do


set_rank :stars, :level => 2, :to => do |commiter|
  commiter.branches > 1 && commiter.followers >= 10

set_rank :stars, :level => 3, :to => do |commiter|
  commiter.branches > 2 && commiter.followers >= 20

Grant manually

You may also add badges/rank "by hand" from controller actions:


MongoMapper support (experimental)

You may use merit with mongo_mapper ORM by calling rails g merit MODEL_NAME --orm mongo_mapper in the third step of the installation, and configuring config.orm = :mongo_mapper in config/initializers/merit.rb.

Notes on upgrades

to 0.3.0

Badges data is now stored in config/initializers/merit.rb using ambry syntax (not in the DB anymore, as that table needed to be in sync in all development environments).

to 0.2.0

Added had_errors boolean attribute to merit_actions table.

To-do list

  • Use ActiveSupport's Array#wrap where I build arrays by hand
  • Ranking should not be badges, so .badges doesn't return them (2-stars shouldn't be badge).
  • :value parameter (for star voting for example) should be configurable (depends on params[:value] on the controller).
  • Make fixtures for integration testing (now creating objects on test file!).


Something went wrong with that request. Please try again.