It would be of great help if some one could help me with an example to implment auto complete feature in my rails application.I tried the jquery auto complete plugin.I was not able to achieve.
My controller:
def new
@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)
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @release }
end
end
I want to create an auto complete for the @testers
view code:
= form.label :tester_tokens, "Testers"
= form.text_field :tester_tokens
Thanks for your help,
Ramya.
Have a look at the Gem rails3-jquery-autocomplete. It should be the base for your implementation. There is even an example application that explains each step you have to take to include it in your application.
At Railscasts.com, you will find an episode that explains how to use it: Autocomplete-association (revised)
If it does not work at all for you, you should come back and ask concrete questions. From your above question, it is not clear where you want to use autocomplete. It is normally used to establish an (additional) association to another object, where you want to replace the drop-down-list or selection-in-list or list of checkboxes by the autocomplete field.
There is an alternative, if you want to have more than one thing selected, have a look at the Railscasts episode “Token Fields”. Because your comment states that this is what you want to do, here are some hints how to do it (copied from my application, you have to replace it by your context, it is a short version of Railscasts 258):
jquery-rails)jquery.tokeninput.jsinto your application (syntax depends on the version you are using).Include the following code in your model (
User??):Include in your
application.jsthe following code:Include in your
TestersControllerthe following code:Change in your view code the following line:
You will find the explanation for all these steps, and some more background at Railscasts episode 258.