可能重复:
error saying “autocomplete method doesn't exist” with rails3-autocomplete 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
在提供捆绑安装时,我能够看到gem:
[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)
请告诉我如何更正此错误。
谢谢, 拉姆亚。
答案 0 :(得分:3)
看起来你需要将autocomplete :users, :name
语句放在新操作之外,这样:
class YourController < ApplicationController
autocomplete :users, :name
def new
end
end