Sha256: 54f43bc055222e44e385acc5024398413ae0388b8434cf06bdc373e5f7b79913

Contents?: true

Size: 894 Bytes

Versions: 4

Compression:

Stored size: 894 Bytes

Contents

module SimpleModel
  module ErrorHelpers

    def errors?
      !self.errors.nil? && !self.errors.empty?
    end

    def errors_for_flash(options={})
      options[:failed_action] ||= "saving"
      options[:id] ||= 'errorExplanation'
      options[:classes] ||= ''
      error_string = "<div id='#{options[:id]}' class='#{options[:classes]}'><h2>#{self.errors.count}"
      if self.errors.length > 1
        error_string << " errors"
      else
        error_string << " error"
      end
      error_string << " prevented #{options[:failed_action]}.</h2><ul>"

      self.errors.full_messages.each do |m|
        error_string << "<li>#{m}</li>"
      end
      error_string << "</ul></div>"
      error_string
    end
  
    def errors_to_s
      error_string = ""
      self.errors.full_messages.each do |m|
        error_string << "#{m} "
      end
      error_string
    end
   
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simple_model-0.2.1 lib/simple_model/error_helpers.rb
simple_model-0.2.0 lib/simple_model/error_helpers.rb
simple_model-0.1.9 lib/simple_model/error_helpers.rb
simple_model-0.1.8 lib/simple_model/error_helpers.rb