semantic_form_for 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,17 +29,23 @@ class SemanticFormFor::FormBuilder < ActionView::Helpers::FormBuilder
29
29
  define_method input do |attribute, *args|
30
30
  options = args.extract_options!
31
31
  text = args.shift
32
+ error = self.object.errors[attribute].try(:join, ', ')
33
+
34
+ classes = [ input ]
35
+ classes << 'error' if error.present?
32
36
 
33
37
  template.capture_haml do
34
- template.haml_tag(:li, :id => _li_id(attribute), :class => input) do
38
+ template.haml_tag(:li, :id => _li_id(attribute), :class => classes) do
35
39
  # check boxes should have their label and input tag in the reverse
36
40
  # order
37
41
  if input != :check_box
38
42
  template.haml_concat self.label(attribute, text)
43
+ template.haml_tag :p, error if error.present?
39
44
  template.haml_concat super(attribute, options)
40
45
  else
41
46
  template.haml_concat super(attribute, options)
42
47
  template.haml_concat self.label(attribute, text)
48
+ template.haml_tag :p, error if error.present?
43
49
  end
44
50
  end
45
51
  end
@@ -56,24 +62,6 @@ class SemanticFormFor::FormBuilder < ActionView::Helpers::FormBuilder
56
62
  end
57
63
  end
58
64
 
59
- def errors(message = nil, &block)
60
- if object.errors.any?
61
- template.capture_haml do
62
- template.haml_tag(:div, :class => 'errors') do
63
- template.haml_tag(:p, message) unless message.blank?
64
- template.haml_tag(:ul) do
65
- self.object.errors.each do |attribute, message|
66
- template.haml_tag :li, case block_given?
67
- when true then yield(attribute, message)
68
- else [ attribute, message ].join(' ')
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
75
- end
76
-
77
65
  private
78
66
 
79
67
  def _object_name
@@ -1,3 +1,3 @@
1
1
  module SemanticFormFor
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Stephen Touset