commit a2692ca7104828ce6da0c747528a18aa17a19501
Author: Yehuda Katz <wycats@Yehuda-Katz.local>
Date: Tue Nov 3 19:25:36 2009 -0800
Some refactoring on UJS helpers
diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb
index 2f6b38d..a48d5a6 100644
--- a/actionpack/lib/action_view/helpers/ajax_helper.rb
+++ b/actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -6,6 +6,7 @@ module ActionView
def remote_form_for(record_or_name_or_array, *args, &proc)
options = args.extract_options!
+ # TODO: Extract duplication with form_for
case record_or_name_or_array
when String, Symbol
object_name = record_or_name_or_array
@@ -74,29 +75,24 @@ module ActionView
end
def observe_field(name, options = {})
- if options[:url]
- options[:url] = options[:url].is_a?(Hash) ? url_for(options[:url]) : options[:url]
- end
+ url = options[:url]
+ options[:url] = url_for(options[:url]) if url && url.is_a?(Hash)
- if options[:frequency]
- case options[:frequency]
- when 0
- options.delete(:frequency)
- else
- options[:frequency] = options[:frequency].to_i
- end
+ frequency = options.delete(:frequency)
+ if frequency && frequency != 0
+ options[:frequency] = frequency.to_i
end
- if options[:with]
- if options[:with] !~ /[\{=(.]/
+ if with = options[:with]
+ if with !~ /[\{=(.]/
options[:with] = "'#{options[:with]}=' + encodeURIComponent(value)"
else
options[:with] ||= 'value' unless options[:function]
end
end
- if options[:function]
- statements = options[:function] # || remote_function(options) # TODO: Need to implement remote function - BR
+ if function = options[:function]
+ statements = function # || remote_function(options) # TODO: Need to implement remote function - BR
options[:function] = JSFunction.new(statements, "element", "value")
end