wycats (owner)

Revisions

gist: 225751 Download_button fork
public
Public Clone URL: git://gist.github.com/225751.git
Embed All Files: show embed
patch.diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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