在 Rails 应用程序中使用 jquery 自动完成 pugin
在我的 Rails 应用程序中,我尝试使用自动完成插件。它不起作用。请在这里帮助我。
查看文件:
%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=>"users_auto_complete"
- @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
@testers=['sramya','scharron','jstinson']
:javascript
data=#{@tmp_testers.to_json}
= javascript_include_tag "pages/ic", :cache => true
控制器文件:
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
Javascript:
$('.users_auto_complete').live("keypress",function() {
var data= #{@tmp_testers.to_json}
alert (data);
$("#release_tester_tokens").autocomplete(data);
});
In my rails application i am trying to use the auto complete plugin.Its not working.Please help me out here.
View file:
%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=>"users_auto_complete"
- @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
@testers=['sramya','scharron','jstinson']
:javascript
data=#{@tmp_testers.to_json}
= javascript_include_tag "pages/ic", :cache => true
Controller file:
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
Javascript:
$('.users_auto_complete').live("keypress",function() {
var data= #{@tmp_testers.to_json}
alert (data);
$("#release_tester_tokens").autocomplete(data);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的jquery在
(document).ready
函数中吗is your jquery is in
(document).ready
function