Sha256: b34a7339cb26536774e7d0cbcaf4c4d23f99b991367a9e05c3e8eaa1e8e4772f

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

module Zena
  module Use
    module ErrorRendering
      module Common

        #TODO: test
        def error_messages_for(type, opts={})
          obj = opts[:object]
          return '' if !obj || obj.errors.empty?
          res = ["<table class='#{opts[:class] || 'errors'}'>"]
          obj.errors.each_error do |er,msg|
            res << "<tr><td><b>#{er}</b></td><td>#{_(msg)}</td></tr>"
          end
          res << '</table>'
          res.join("\n")
        end

        # TODO: test (where is this used ? discussions, ?)
        def processing_error(msg)
          # (this method used to be called add_error, but it messed up with 'test/unit/testcase.rb' when testing helpers)
          @errors ||= []
          @errors << _(msg)
        end

        # TODO: test
        def render_errors(errs=@errors)
          if !errs || errs.empty?
            ""
          elsif errs.kind_of?(ActiveRecord::Errors)
            res = "<table class='errors'>"
            errs.each do |k,v|
              res << "<tr><td><b>#{k}</b></td><td>#{v}</td></tr>\n"
            end
            res << "</table>"
            res
          else
            "<table class='errors'><tr><td>#{errs.join("</td></tr>\n<tr><td>")}</td></tr></table>"
          end
        end

      end # Common

      module ControllerMethods
        include Common
      end

      module ViewMethods
        include Common
      end

    end # ErrorRendering
  end # Use
end # Zena

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
zena-1.2.8 lib/zena/use/error_rendering.rb
zena-1.2.7 lib/zena/use/error_rendering.rb
zena-1.2.6 lib/zena/use/error_rendering.rb
zena-1.2.5 lib/zena/use/error_rendering.rb
zena-1.2.4 lib/zena/use/error_rendering.rb
zena-1.2.3 lib/zena/use/error_rendering.rb
zena-1.2.2 lib/zena/use/error_rendering.rb
zena-1.2.1 lib/zena/use/error_rendering.rb
zena-1.2.0 lib/zena/use/error_rendering.rb
zena-1.1.3 lib/zena/use/error_rendering.rb
zena-1.1.2 lib/zena/use/error_rendering.rb
zena-1.1.1 lib/zena/use/error_rendering.rb
zena-1.1.0 lib/zena/use/error_rendering.rb
zena-1.0.0 lib/zena/use/error_rendering.rb
zena-1.0.0.rc3 lib/zena/use/error_rendering.rb