An easy to use Rails plugin to quickly throttle application actions based on configurable duration and limit.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is even with fredwu:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Action Throttler

There is also a PHP version (for Kohana), see here:


Action Throttler is an easy to use Rails plugin to quickly throttle application actions based on configurable duration and limit.

Brought to you by Envato and Wuit.


  • Easy to use, easy to configure
  • Lightweight
  • Supports both Rails 2 and 3


  • Supports ActiveRecord only
  • Uses Rake instead of Rails Generator for file generation (for compatibility purpose)


Download and install the plugin

Rails 2

script/plugin install

Rails 3

rails plugin install

Set up the plugin

To generate the migration file and migrate the database:

rake action_throttler:migrate
rake db:migrate

Or alternatively:

rake action_throttler:auto_migrate

Configure the actions

The configuration file is located at PATH_TO_YOUR_APP/config/initializers/action_throttler.rb.

The configuration block looks like this:

ActionThrottler::Actions.add :mail do |action|
  action.duration = 1.hour
  action.limit    = 10

You can add as many configuration blocks as you like, just make sure you label them properly (i.e. like :mail in the example).

In the example, we are setting the :mail action to perform at most 10 times within 1 hour duration.

Register the actions in your app

Now we will need to register the actions so they are recorded in the database.

To simply run an action, in your app (presumably somewhere in the controller), do this: will return true or false depending on whether or not the action is being throttled. has an alias ActionThrottler::Actions.can_run and a negative alias ActionThrottler::Actions.cannot_run.

Typically, we would want to produce feedback to the user when an action is throttled, you can do so by:

if ActionThrottler::Actions.cannot_run(:mail)
  # tell the user that this action is not performed
end also takes an optional reference parameter:, @current_user)

The reference parameter is very useful because we can track and throttle the action based on a reference, such as a user. The parameter accepts a String, an Integer or an ActiveRecord object.

Note that and its aliases will perform the action when possible. If you only want to check to see if an action can be performed, you can do this:

ActionThrottler::Actions.can_be_run?(:mail, @current_user)

ActionThrottler::Actions.can_be_run? returns true or false without performing the action, and it also has a negative alias, ActionThrottler::Actions.cannot_be_run?.


Copyright (c) 2010 Fred Wu (, released under the MIT license