Sha256: bfc7456b3bf7e8d4e5846a261977304d95f0c55ffc49e725de4212e711b322a3

Contents?: true

Size: 1.71 KB

Versions: 15

Compression:

Stored size: 1.71 KB

Contents

# Loose the div around fields with errors
ActionView::Base.field_error_proc = lambda {|tag, _| tag}



# So we get error messages wrapped in a span instead of a div which will tend to mess up forms
module ActionView::Helpers::ActiveRecordHelper  	

  def error_message_on(object, method, *args)
    options = args.extract_options!
    unless args.empty?
      ActiveSupport::Deprecation.warn('error_message_on takes an option hash instead of separate ' +
        'prepend_text, append_text, and css_class arguments', caller)

      options[:prepend_text] = args[0] || ''
      options[:append_text] = args[1] || ''
      options[:css_class] = args[2] || 'formError'
    end
    options.reverse_merge!(:prepend_text => '', :append_text => '', :css_class => 'formError')

    if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
      (errors = obj.errors.on(method))
      content_tag("span",
        "#{options[:prepend_text]}#{errors.is_a?(Array) ? errors.first : errors}#{options[:append_text]}",
        :class => options[:css_class]
      )
    else
      ''
    end
  end

end




#
# Allow some application_helper methods to be used in the scoped form_for manner
#
class ActionView::Helpers::FormBuilder
  
  def label(method, text = nil, options={})
    @template.label(@object_name,method,text,options)
  end

  def field_container(method, options = {}, &block)
    @template.field_container(@object_name,method,options,&block)
  end

  %w(error_message_on).each do |selector|
    src = <<-end_src
      def #{selector}(method, options = {})
        @template.send(#{selector.inspect}, @object_name, method, objectify_options(options))
      end
    end_src
    class_eval src, __FILE__, __LINE__
  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
spree-0.11.4 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.11.3 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.11.2 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.11.1 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.11.0 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.10.2 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.10.1 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.10.0 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.10.0.beta lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-enriquez-0.9.4 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.9.4 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.9.3 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.9.2 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.9.1 lib/plugins/monkey_patches/lib/monkey_patches.rb
spree-0.9.0 lib/plugins/monkey_patches/lib/monkey_patches.rb