Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Created February 16, 2009 22:16
Show Gist options
  • Save coryodaniel/65408 to your computer and use it in GitHub Desktop.
Save coryodaniel/65408 to your computer and use it in GitHub Desktop.
class TestUsingBeforeFilter < Application
before :captcha_every_time!, :only => [:create,:destroy]
before :captcha_once_per_30_seconds!, :only => [:index], :unless => :is_admin?
def index
render
end
def create
render "Awesome form here"
end
def destroy
render "I am the destroyer"
end
protected
def is_admin?
!!(session[:is_admin])
end
def captcha_every_time!
threshold()
end
def captcha_once_per_30_seconds!
threshold :frequency => 1.per(30.seconds)
end
end
class TestUsingClassMethod < Application
threshold :create, :destroy
threshold :index, :frequency => 1.per(30.seconds), :unless => :is_admin?
protected
def is_admin?
!!(session[:is_admin])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment