使用rails3-autocomplete gem说“自动完成方法不存在”的错误

时间:2011-12-30 09:13:49

标签: jquery ruby-on-rails autocomplete rubygems

在我的rails应用程序中,我正在尝试使用rails3-jquery-autocomplete gem。 我在Gemfile中包含以下行。 'gem rails3-jquery-autocomplete'并提供了bundle install并将其列在gem中。

我的控制器:

class ReleasesController < AuthorizedController
  # GET /releases
  # GET /releases.xml
    autocomplete :users, :name 

     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

  end

路线档案:

get 'releases/autocomplete_users_name'

查看文件:

= autocomplete_field_tag 'tester_name', '', users_autocomplete_user_name_path, :size => 75 

我收到错误

undefined method `autocomplete' for #<ReleasesController:0xb731e2c0>

请帮帮我。

谢谢, 拉姆亚。

1 个答案:

答案 0 :(得分:1)

你运行了发电机吗? rails generate autocomplete:install

在控制器内它应该是

 Class SomeController
 autocomplete :user, :name 
   def yourmethods
   end
 end   

请查看此处的说明: https://github.com/crowdint/rails3-jquery-autocomplete