Browse files

* changed with_custom_field_error_proc to use ensure for restoring de…

…fault field_error_proc and to store it in a local variable instead of in a class variable (nested calls were problematic due to the globalness of class variables)
  • Loading branch information...
1 parent 12029dc commit 03361977787fac14cb3342c73f0b20fad76e3797 @mtarnovan mtarnovan committed Jul 14, 2010
Showing with 6 additions and 8 deletions.
  1. +6 −8 lib/formtastic.rb
View
14 lib/formtastic.rb
@@ -1724,9 +1724,7 @@ def escape_html_entities(string) #:nodoc:
module SemanticFormHelper
@@builder = ::Formtastic::SemanticFormBuilder
mattr_accessor :builder
-
- @@default_field_error_proc = nil
-
+
# Override the default ActiveRecordHelper behaviour of wrapping the input.
# This gets taken care of semantically by adding an error class to the LI tag
# containing the input.
@@ -1736,13 +1734,13 @@ module SemanticFormHelper
end
def with_custom_field_error_proc(&block)
- @@default_field_error_proc = ::ActionView::Base.field_error_proc
+ default_field_error_proc = ::ActionView::Base.field_error_proc
::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
- result = yield
- ::ActionView::Base.field_error_proc = @@default_field_error_proc
- result
+ yield
+ ensure
+ ::ActionView::Base.field_error_proc = default_field_error_proc
end
-
+
[:form_for, :fields_for, :remote_form_for].each do |meth|
module_eval <<-END_SRC, __FILE__, __LINE__ + 1
def semantic_#{meth}(record_or_name_or_array, *args, &proc)

0 comments on commit 0336197

Please sign in to comment.