<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,38 +1,40 @@
 module JsonAutocompleteHelper
-  
+
   def json_autocomplete(record, association, choices_url, options = {})
     current_id      = record.send(&quot;#{association}_id&quot;)
     current_name    = record.send(association).to_s
-    
+
     dom_id_base     = options[:dom_id_base]   || dom_id(record)
     dom_name_base   = options[:dom_name_base] || record.class.name.underscore
-    
+
     base_field_id   = &quot;#{dom_id_base}_#{association}&quot;
-    
+
     id_field_name   = &quot;#{dom_name_base}[#{association}_id]&quot;
     type_field_name = &quot;#{dom_name_base}[#{association}_type]&quot;
-    
+
     js_var_name     = options[:js_var_name] || base_field_id;
-    
+
     width           = options[:width] || &quot;30ex&quot;
-    
+
     as_user_id      = options[:as_user]
-    as_user_id      = as_user_id.id if as_user_id.kind_of?(User)
-    
+    as_user_id      = as_user_id.id if as_user_id &amp;&amp; !as_user_id.kind_of?(Integer)
+
     on_change       = options[:onchange] || &quot;null&quot;
 
     label_attribute = options[:label_attribute] || &quot;name&quot;
-    
+
+    choices_url = url_for(choices_url) if choices_url.kind_of?(Hash)
+
     if as_user_id
       choices_url &lt;&lt; (choices_url.include?('?') ? &quot;&amp;&quot; : &quot;?&quot;) + &quot;perform_as_user_id=#{as_user_id}&quot;
     end
-    
+
     if options[:with]
       with = &quot;'#{choices_url.include?('?') ? &quot;&amp;&quot; : &quot;?&quot;}' + #{options[:with]}&quot;
     else
       with = &quot;''&quot;
     end
-    
+
     if options[:with_form_elements]
       wfe = &quot;&quot;
       if options[:with_form_elements].kind_of?(Hash)
@@ -52,17 +54,17 @@ module JsonAutocompleteHelper
       wfe = 'null'
     end
     with_form_elements = wfe
-    
-    
+
+
     # modify the URL to make sure we're requesting a response in JSON format
     choices_url.sub!(/\?|$/, &quot;.json#{'?' if choices_url.include?('?')}&quot;) unless choices_url.include? '.json'
-    
+
     style = options[:style] || &quot;&quot;
-    
+
     if width
       style &lt;&lt; &quot;; width: #{width}&quot;
     end
-    
+
     type_field = %{&lt;input type=&quot;hidden&quot; name=&quot;#{type_field_name}&quot; id=&quot;#{base_field_id}_type&quot; class=&quot;type&quot; /&gt;} if options[:include_type_field]
     autocomplete_field = %{&lt;input type=&quot;text&quot;   name=&quot;#{base_field_id}_autocomplete&quot; style=&quot;width: #{width}&quot; id=&quot;#{base_field_id}_autocomplete&quot; class=&quot;text&quot; value=&quot;#{current_name}&quot; /&gt;}
 
@@ -75,23 +77,24 @@ module JsonAutocompleteHelper
       &lt;/div&gt;
     }
 
-    container = ActionView::Base.field_error_proc.call(container, self) if record.errors.on(&quot;#{association}&quot;) || record.errors.on(&quot;#{association}_id&quot;)
-    
+    container = ActionView::Base.field_error_proc.call(container, self) if record.errors &amp;&amp;
+      (record.errors.on(&quot;#{association}&quot;) || record.errors.on(&quot;#{association}_id&quot;))
+
     javascript = javascript_tag %{
       var #{js_var_name} = new JSON.Autocompleter(
-        '#{base_field_id}_autocomplete_container', 
-        '#{base_field_id}_options', 
+        '#{base_field_id}_autocomplete_container',
+        '#{base_field_id}_options',
         '#{choices_url}',
         {
-          'parameters': #{with}, 
-          'withFormElements': #{with_form_elements}, 
+          'parameters': #{with},
+          'withFormElements': #{with_form_elements},
           'onchange': #{on_change},
           'labelAttribute': '#{label_attribute}'
         }
       )
     }
-    
+
     return container + javascript
   end
-  
+
 end
\ No newline at end of file</diff>
      <filename>lib/json_autocomplete_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b509704f18d08e7eeb5a479d7a83e7760aceb8e7</id>
    </parent>
  </parents>
  <author>
    <name>Matt Zukowski</name>
    <email>matt@zukowski.ca</email>
  </author>
  <url>http://github.com/zuk/json_autocompleter/commit/1cc2510536883cc56a6c2b41ba77efcd4f5ef40b</url>
  <id>1cc2510536883cc56a6c2b41ba77efcd4f5ef40b</id>
  <committed-date>2009-09-24T20:54:26-07:00</committed-date>
  <authored-date>2009-09-24T20:54:26-07:00</authored-date>
  <message>better handling of sketchy arguments</message>
  <tree>35b324323785542c2db2e9aeb91a22a9d4b2cf62</tree>
  <committer>
    <name>Matt Zukowski</name>
    <email>matt@zukowski.ca</email>
  </committer>
</commit>
