NoMethodError for auto complete with rails3 autocomplete gem



可能的重复项:
使用 RailS3 自动完成 gem 时显示"自动完成方法不存在"时出错

我正在尝试使用 rails3-jquery-autocomplete gem 实现自动完成。我收到一条错误消息,说

NoMethodError (undefined method `autocomplete' for #<ReleasesController:0xb76febec>):
  app/controllers/releases_controller.rb:41:in `new'

我安装了 gem,并在我的控制器中使用它作为

控制器代码:

def new
autocomplete :users, :name 
end

查看文件:

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

在提供捆绑安装时,我能够看到宝石:

[root@sanduxvm01 trunk]# bundle install
Using rake (0.9.2)
Using abstract (1.0.0)
Using activesupport (3.0.10)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.10)
Using erubis (2.6.6)
Using rack (1.2.4)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.30)
Using actionpack (3.0.10)
Using mime-types (1.16)
Using polyglot (0.3.2)
Using treetop (1.4.10)
Using mail (2.2.19)
Using actionmailer (3.0.10)
Using arel (2.0.10)
Using activerecord (3.0.10)
Using activeresource (3.0.10)
Using bcrypt-ruby (2.1.4)
Using bundler (1.0.17)
Using cancan (1.6.7)
Using cocaine (0.2.0)
Using orm_adapter (0.0.5)
Using warden (1.0.6)
Using devise (1.4.2)
Using dynamic_form (1.1.4)
Using formtastic (1.2.4)
Using haml (3.1.3)
Using json (1.6.1)
Using rdoc (3.11)
Using thor (0.14.6)
Using railties (3.0.10)
Using jquery-rails (1.0.16)
Using paperclip (2.4.4)
Using pg (0.11.0)
Using rails (3.0.10)
Using rails3-jquery-autocomplete (1.0.5)
Using will_paginate (3.0.pre2)

请让我知道如何更正此错误。

谢谢拉米亚。

看起来您需要autocomplete :users, :name语句从新操作中取出,这样:

class YourController < ApplicationController
  autocomplete :users, :name 
  def new
  end
end

最新更新