Module: ValidationRage::ControllerExtension
- Defined in:
- lib/validation_rage/controller_extension.rb
Instance Method Summary collapse
- #notify_validation_rage ⇒ Object
- #validation_rage_context ⇒ Object
- #validation_rage_errors_present?(var_name) ⇒ Boolean
Instance Method Details
#notify_validation_rage ⇒ Object
4 5 6 7 8 9 |
# File 'lib/validation_rage/controller_extension.rb', line 4 def notify_validation_rage objects_with_errors = self.instance_variables.collect {|var_name| instance_variable_get(var_name) if validation_rage_errors_present?(var_name) }.compact objects_with_errors.each do |o| ActiveSupport::Notifications.publish("validation_rage:errors", {o.class.name => o.errors.to_hash, :context => self.validation_rage_context }) end end |
#validation_rage_context ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/validation_rage/controller_extension.rb', line 17 def validation_rage_context { :controller => params[:controller], :action => params[:action], :request_path => request.path, :params => request.filtered_parameters, :request_uuid => request.uuid, :referrer => request.referrer } end |
#validation_rage_errors_present?(var_name) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/validation_rage/controller_extension.rb', line 11 def validation_rage_errors_present?(var_name) return false if var_name.to_s =~ /^@_/ # ignore variable names marked with "_" - those are by convention internal only obj = instance_variable_get(var_name) obj.respond_to?(:errors) && !obj.errors.empty? end |