Class: Instructions::FieldError
- Inherits:
-
Object
- Object
- Instructions::FieldError
- Defined in:
- lib/instructions/field_error.rb
Class Method Summary collapse
- .field_error_proc ⇒ Object
- .render_field_with_error(html_tag, error_data) ⇒ Object
- .wrap_html_tag_with_field_with_errors_div(html_tag) ⇒ Object
- .wrap_label_tag_with_field_with_errors_label_div(div_tag) ⇒ Object
Class Method Details
.field_error_proc ⇒ Object
3 4 5 6 7 |
# File 'lib/instructions/field_error.rb', line 3 def self.field_error_proc Proc.new do |html_tag, error_data| render_field_with_error(html_tag, error_data).html_safe end end |
.render_field_with_error(html_tag, error_data) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/instructions/field_error.rb', line 9 def self.render_field_with_error(html_tag, error_data) if html_tag =~ /^<label/ return wrap_label_tag_with_field_with_errors_label_div(html_tag) end model = error_data.object model_name = error_data.object_name attribute_name = error_data.method_name human_attribute_name = model.class.human_attribute_name(attribute_name) attribute_errors = model.errors[attribute_name.to_sym] field_with_errors_div = wrap_html_tag_with_field_with_errors_div(html_tag) "#{field_with_errors_div}" end |
.wrap_html_tag_with_field_with_errors_div(html_tag) ⇒ Object
25 26 27 |
# File 'lib/instructions/field_error.rb', line 25 def self.wrap_html_tag_with_field_with_errors_div(html_tag) "<div class=\"field_with_errors\">#{html_tag}</div>" end |
.wrap_label_tag_with_field_with_errors_label_div(div_tag) ⇒ Object
29 30 31 |
# File 'lib/instructions/field_error.rb', line 29 def self.wrap_label_tag_with_field_with_errors_label_div(div_tag) "<div class=\"field_with_errors_label\">#{div_tag}</div>" end |