在 Rails 应用程序中使用 jquery 自动完成 pugin

发布于 2024-12-22 21:00:07 字数 1439 浏览 1 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-12-29 21:00:07

你的jquery在(document).ready函数中吗

$(document).ready(function(){

$('.users_auto_complete').live("keypress",function() {
var data= #{@tmp_testers.to_json}
alert (data);
$("#release_tester_tokens").autocomplete(data);
});

});

is your jquery is in (document).ready function

$(document).ready(function(){

$('.users_auto_complete').live("keypress",function() {
var data= #{@tmp_testers.to_json}
alert (data);
$("#release_tester_tokens").autocomplete(data);
});

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文