My requirement is to implement auto complete feature in my rails application. I need to convert the @testers in my controller code below to json format.
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)
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @release }
end
end
In my view code i tried this:
%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,:class => 'autocomplete'
:javascript
data = #{testers.to_json}
I am getting undefined for data.
Please help me out here.
Thanks,
Ramya.
To create a json source you can add
format.jsonto the respond_to loop liek this:If you dont want to extract all the data
onlyandexceptoptions are available. You should be able to use this for the most autocomplete plugins!By adding the
qdata you will be able to demarcate the results by given pattern.