0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Adds nonces to your Rails' forms
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 2.0

Runtime

~> 3.0
 Project Readme

Double Trouble¶ ↑

Adds nonces to your Rails’ forms, avoiding duplicates by sending the same form again (when the user has ADHD, as well in the other situations).

Installation¶ ↑

gem install double_trouble

Usage¶ ↑

class CommentsController < ApplicationController
  protect_from_double_trouble :comment, :only => :create

  def create
    @comment = Comment.new(params[:comment])
    if @comment.save
      # ordinary stuff
    end
  end
end

Double trouble works quite similar to CSRF protection (authenticity_token) - it adds form_nonce parameter to your forms. After the protected model is successfully saved (when new_record? returns false), it stores received form_nonce in the Rails.cache by default (you can easily replace the default store by DB backend for instance).

Configuration¶ ↑

You can globally turn the protection off (test environment?):

ActionController::Base.allow_double_trouble_protection = false

Default nonce store can be changed:

ActionController::Base.double_trouble_nonce_store = FormNonce

FormNonce class must implement two class methods:

def self.valid?(nonce)
  # checks if the nonce has not been used before
end

def self.store!(nonce)
  # stores the given nonce somewhere
end

The name of the form nonce param can be changed as well:

ActionController::Base.double_trouble_nonce_param = :double_trouble_nonce

Copyright © 2010 Jakub Kuźma. See LICENSE for details.