My requirement is to implement auto complete in my text box with my rails application
I have downloaded the jquery auto complete plugin.Please help me with how to implement it .
My controller code:
def new
@release = Release.new
@ic_ids = params[:ic_ids] ? params[:ic_ids] : []
**@testers = User.find_by_sql("select * from users where id in(select user_id from user_role_assignments where role_id in (select id from roles where name like 'Tester')) order by name").paginate(:page=>params[:page],:per_page=>30)**
if params[:project_id]
@release.project = Project.find(params[:project_id])
end
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @release }
end
end
I want to create auto complete for @testers.
My view code:
%td.grid.full_panels
-table_panel "Assign Testers" do
%table
%th Name
-puts "testers=#{@testers}"
= form.label :tester_tokens, "Testers"
**= form.text_field :tester_tokens**
Thanks,
Ramya.
When you implement auto-complete, there’s really 2 ways to approach it.
For the first method, there’s a really cool jquery plugin called jsonSuggest
and it’s really easy to implement.
You need a json object in (id,text) pairs like so :
var myData = [{ id : "someId" , text : "someText"} , ... ]and then you invoke the following code :
$("#myInput").jsonSuggest({ data : myData , onSelect: function(item){ /* callback code */} })This can fit even for thousands of objects. It will give a better performance that multiple ajax calls to the server.
If you rather use the jquery-ui plugin, have a look at the default example
The other method (multiple ajax requests) is quite similar, but I don’t think that jsonsuggest supports it. It is supported by the jquery-ui plugin.
For this case, you should have a look at the remote example