Skip to content


Subversion checkout URL

You can clone with
Download ZIP
100644 34 lines (27 sloc) 1.65 KB
8eac38f @sikachu Extract module and tests from rails
sikachu authored
1 This module provides a class-level method for specifying that certain
2 actions are guarded against being called without certain prerequisites
3 being met. This is essentially a special kind of before_filter.
5 An action may be guarded against being invoked without certain request
6 parameters being set, or without certain session values existing.
8 When a verification is violated, values may be inserted into the flash, and
9 a specified redirection is triggered. If no specific action is configured,
10 verification failures will by default result in a 400 Bad Request response.
12 Usage:
14 class GlobalController < ActionController::Base
15 # Prevent the #update_settings action from being invoked unless
16 # the 'admin_privileges' request parameter exists. The
17 # settings action will be redirected to in current controller
18 # if verification fails.
19 verify :params => "admin_privileges", :only => :update_post,
20 :redirect_to => { :action => "settings" }
22 # Disallow a post from being updated if there was no information
23 # submitted with the post, and if there is no active post in the
24 # session, and if there is no "note" key in the flash. The route
25 # named category_url will be redirected to if verification fails.
27 verify :params => "post", :session => "post", "flash" => "note",
28 :only => :update_post,
29 :add_flash => { "alert" => "Failed to create your message" },
30 :redirect_to => :category_url
32 Note that these prerequisites are not business rules. They do not examine
33 the content of the session or the parameters. That level of validation should
34 be encapsulated by your domain model or helper methods in the controller.
Something went wrong with that request. Please try again.