Module: FormHelper::ErrorMessages

Defined in:
lib/form_helper/error_messages.rb,
lib/form_helper/error_messages/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#error_messages(attr, opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/form_helper/error_messages.rb', line 3

def error_messages(attr, opts={})
  tag        = opts[:tag]   || :div
  class_name = opts[:class] || 'invalid'
  errors = @object.errors
  errors[attr].map{|message|
    message = errors.full_message(attr, message)
    if block_given?
      yield message
    else
      @template.(tag, ERB::Util.html_escape(message), class: class_name)
    end
  }.join("\n").html_safe
end