# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def in_place_editor_field_with_local_autocomplete(object, method, tag_options = {}, in_place_editor_options = {}, autocomplete_options = {}) tag = ::ActionView::Helpers::InstanceTag.new(object, method, self) tag_options = { :tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options) in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id }) tag.to_content_tag(tag_options.delete(:tag), tag_options) + in_place_editor_with_local_autocomplete(tag_options[:id], in_place_editor_options, autocomplete_options) end def in_place_editor_with_local_autocomplete(field_id, options = {}, autocomplete_options = {}) function = "new Ajax.InPlaceEditorWithLocalAutocomplete(" function << "'#{field_id}', " function << "'#{url_for(options[:url])}', " function << options_for_javascript( { 'catalog' => autocomplete_options.delete(:catalog), 'autocomplete_options' => options_for_javascript( autocomplete_options ) } ) function << ')' javascript_tag(function) end end