After some further tinkering, I’m able to get ‘goodguy’ and ‘badguy’
values passed to the controller (the ‘method per id’ is far from
ideal…):
entry.rhtml
<p>
<label for="attr_badguy_name">Bad Guy:</label>
<%=
text_field_with_auto_complete_with_id_checking :entity, :name, { :id
=> “badguy” }, { :with => “‘badguy[name]=’ + $(‘badguy’).value +
‘&entity[schema_type]=complex’”} %>
Good Guy:
<%=
text_field_with_auto_complete_with_id_checking :goodguy, :name, { :id
=> “goodguy” }, { :with => “‘goodguy[name]=’ + $(‘goodguy’).value” }
%>
module ApplicationHelper
def text_field_with_auto_complete_with_id_checking(object, method,
tag_options = {},
completion_options = {})
# lets just set the id now and not worry about it throughout
id = tag_options[:id] || “#{object}_#{method}”
print “\n\n\n\t\t”
pp id
(completion_options[:skip_style] ? "" : auto_complete_stylesheet)
- text_field(id, method, tag_options) +
content_tag(“div”, “”, :id => “#{id}auto_complete", :class
=>“auto_complete”) +
auto_complete_field(id, { :url => { :action =>
"auto_complete_for#{id}_#{method}” } }.update(completion_options))
end
class AttrController < ApplicationController
protect_from_forgery :only => [:create, :update, :destroy]
def auto_complete_for_goodguy_name
print “\n\n\t\tin auto_complete_for_goodguy_name\n”
pp params
org = params[:person][:org].nil? ? “” : “org=’” + params[:person]
[:org] + “’”
re = Regexp.new("^#{params[:goodguy][:name]}", “i”)
find_options = { :conditions => org, :order => “name ASC” }
@people = Person.find(:all, find_options).collect(&:name).select
{ |person| person.match re }
render :inline => "<%= content_tag(:ul, @people.map { |person|
content_tag(:li, h(person)) }) %>"
end
def auto_complete_for_badguy_name
print “\n\n\t\tin auto_complete_for_badguy_name\n”
pp params
org = params[:person][:org].nil? ? “” : “org=’” + params[:person]
[:org] + “’”
re = Regexp.new("^#{params[:badguy][:name]}", “i”)
find_options = { :conditions => org, :order => “name ASC” }
@people = Person.find(:all, find_options).collect(&:name).select
{ |person| person.match re }
render :inline => "<%= content_tag(:ul, @people.map { |person|
content_tag(:li, h(person)) }) %>"
end