Module: JqueryAutoCompleteJson

Includes:
ActionView::Helpers::JavaScriptHelper, HandleAttributes
Included in:
Array
Defined in:
lib/jquery/jquery_auto_complete.rb

Instance Method Summary collapse

Methods included from ActionView::Helpers::JavaScriptHelper

#javascript_function, #jquery_id, #jquery_ids

Instance Method Details

#to_auto_complete(format, attributes) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jquery/jquery_auto_complete.rb', line 27

def to_auto_complete(format, attributes)
  case format
    when :json
      json = %Q([)
      each do |elem|
        couples = elem.attributes.symbolize_keys
        json << %Q({ "id": "#{get_atr_value(elem, attributes[0], couples)}",)
        json << %Q( "label": "#{get_atr_value(elem, attributes[1], couples)}",)
        json << %Q( "value": "#{get_atr_value(elem, attributes[2], couples).gsub(/<\/?[^>]*>/, "")}" },)
      end
      json.chop! << " ]"
  end
end