Sha256: 0cc7810065c24d9980a074899e079c54c0da4ef04ed78df515e0ea7dfb837e3b

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

module SimpleForm
  module Components
    module Errors
      def error(wrapper_options = nil)
        error_text if has_errors?
      end

      def full_error(wrapper_options = nil)
        full_error_text if options[:error] != false && has_errors?
      end

      def has_errors?
        object && object.respond_to?(:errors) && errors.present?
      end

      protected

      def error_text
        text = has_custom_error? ? options[:error] : errors.send(error_method)

        "#{html_escape(options[:error_prefix])} #{html_escape(text)}".lstrip.html_safe
      end

      def full_error_text
        has_custom_error? ? options[:error] : full_errors.send(error_method)
      end

      def error_method
        options[:error_method] || SimpleForm.error_method
      end

      def errors
        @errors ||= (errors_on_attribute + errors_on_association).compact
      end

      def full_errors
        @full_errors ||= (full_errors_on_attribute + full_errors_on_association).compact
      end

      def errors_on_attribute
        object.errors[attribute_name]
      end

      def full_errors_on_attribute
        object.errors.full_messages_for(attribute_name)
      end

      def errors_on_association
        reflection ? object.errors[reflection.name] : []
      end

      def full_errors_on_association
        reflection ? object.errors.full_messages_for(reflection.name) : []
      end

      def has_custom_error?
        options[:error].is_a?(String)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
simple_form-3.5.0 lib/simple_form/components/errors.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/simple_form-3.4.0/lib/simple_form/components/errors.rb
simple_form-3.4.0 lib/simple_form/components/errors.rb
simple_form-3.3.1 lib/simple_form/components/errors.rb
simple_form-3.3.0 lib/simple_form/components/errors.rb
simple_form-3.2.1 lib/simple_form/components/errors.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/simple_form-3.2.0/lib/simple_form/components/errors.rb
simple_form-3.2.0 lib/simple_form/components/errors.rb
simple_form-3.1.1 lib/simple_form/components/errors.rb
simple_form-3.1.0 lib/simple_form/components/errors.rb