I want to implement auto complete feature in a rails application. I am using the jquery auto complete plugin.
I want to implement the auto complete feature for the following array.
@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)
I want to pass this in json format to the .js file. I tried using the below code code in my view file.But the auto complete is not populating the data.
= form.label :tester_tokens, "Testers"
= form.text_field :tester_tokens
- @testers.each do |tester|
%tr
%td=tester.name
%td=check_box_tag "release[tester_ids][]", tester.id, @release.is_tester_assigned(tester)
//=will_paginate @testers
:javascript
var data="#{escape_javascript @testers.to_json}";
= javascript_include_tag :defaults,:cache => true
My .js file:
$(document).ready(function() {
$.parseJSON(data);
alert (data);
$('#release_tester_tokens').autocomplete({source:data});
});
Please help me out here.
You’re discarding the value returned by
$.parseJSON.