Class AuditsController
In: app/controllers/audits_controller.rb
Parent: ApplicationController
File:audits_controller.rb
(C):Hipposoft 2008, 2009
Purpose:Manage Acts As Audited tables.

          20-Jan-2008 (ADH): Created.

Methods

index  

Public Instance methods

List audit information.

[Source]

    # File app/controllers/audits_controller.rb, line 18
18:   def index
19: 
20:     # Set up the column data; see the index helper functions in
21:     # application_helper.rb for details.
22: 
23:     @columns = [
24:       { :header_text  => 'When?',    :value_helper => :apphelp_created_at,       :sort_by => 'created_at'     },
25:       { :header_text  => 'Who?',     :value_helper => :audithelp_user_name,      :sort_by => 'users.name'     },
26:       { :header_text  => 'What?',    :value_helper => :audithelp_type_of_change, :sort_by => 'auditable_type' },
27:       { :header_text  => 'Changes',  :value_helper => :audithelp_changes,                                     },
28:       { :header_text  => 'Revision', :value_method => :version,
29:         :header_align => 'center',   :value_align  => 'center'                                                },
30:     ]
31: 
32:     # Get the basic options hash from ApplicationController, then handle
33:     # search forms.
34: 
35:     options = appctrl_index_assist( Audit )
36:     conditions_vars = {}
37: 
38:     unless ( params[ :search ].nil? )
39:       if ( params[ :search ].empty? or params[ :search_cancel ] )
40:         params.delete( :search )
41:       else
42:         search_num      = params[ :search ].to_i
43:         search_str      = "%#{ params[ :search ] }%" # SQL wildcards either side of the search string
44:         conditions_sql  = 'WHERE ( action ILIKE :search_str OR auditable_type ILIKE :search_str OR users.name ILIKE :search_str OR version ILIKE :search_num )'
45:         conditions_vars = { :search_num => search_num, :search_str => search_str }
46:       end
47:     end
48: 
49:     # Sort order is already partially compiled in 'options' from the earlier
50:     # call to 'appctrl_index_assist'.
51: 
52:     order_sql = "ORDER BY #{ options[ :order ] }"
53:     options.delete( :order )
54: 
55:     # Construct the query.
56: 
57:     finder_sql = "SELECT audits.* FROM audits\n" <<
58:                  "LEFT OUTER JOIN users ON ( audits.user_id = users.id )\n" <<
59:                   "#{ conditions_sql }\n" <<
60:                   "#{ order_sql      }"
61: 
62:     # Now paginate using this SQL query.
63: 
64:     @audits = Audit.paginate_by_sql( [ finder_sql, conditions_vars ], options )
65:   end

[Validate]