自动完成字段栏出现问题
我正在尝试实现 SO 风格的自动完成。我正在使用这个 gem 下载必要的rails3-jquery-autocomplete。
这是我的控制器:
autocomplete :tag, :name
我的布局有这个:
<%= javascript_include_tag :defaults, "autocomplete-rails.js" %>
我的路线有这个:
resources :posts do
get :autocomplete_tag_name, :on => :collection
end
我的表单有这个:
<%= f.autocomplete_field :tag_list, autocomplete_tag_name_posts_path, :"data-delimiter" => ', ', :class => "tags" %>
我的 public/javascript 文件夹中有 autocomplete-rails.js 。但由于某种原因,我不断收到此错误:
undefined method `autocomplete_field' for #<ActionView::Helpers::FormBuilder:0x0000011cb94ef8>.
我的environment.rb 文件如下所示:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
NutraNation::Application.initialize!
我做错了什么?一些帮助会让我永远感激你。
I am trying to implement SO style autocomplete. I am using this gem to download the necessary rails3-jquery-autocomplete.
Here is my controller:
autocomplete :tag, :name
My layout has this:
<%= javascript_include_tag :defaults, "autocomplete-rails.js" %>
My routes has this:
resources :posts do
get :autocomplete_tag_name, :on => :collection
end
And my form has this:
<%= f.autocomplete_field :tag_list, autocomplete_tag_name_posts_path, :"data-delimiter" => ', ', :class => "tags" %>
I have the autocomplete-rails.js in my public/javascript folder. Yet for some reason I keep getting this error:
undefined method `autocomplete_field' for #<ActionView::Helpers::FormBuilder:0x0000011cb94ef8>.
My environment.rb file looks like this:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
NutraNation::Application.initialize!
What am I doing wrong? Some help would leave me forever in your debt.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误是 Rails 错误,而不是 javascript 错误。该错误基本上意味着您正在调用不存在的辅助方法 (
autocomplete_field
)。看起来您没有将 auto_complete gem 包含在正确的位置。检查您的
%APP_ROOT/config/environment.rb
文件,并确保您的 gem 包含在其中。另外,请确保您已在助手中包含了所有必要的资源。 gem 的安装说明应该解释您需要检查的任何/所有内容,以确保其设置正确。
This error is a Rails error, not a javascript error. The error basically means you're calling a helper method (
autocomplete_field
) that doesn't exist.Looks like you're not including the auto_complete gem in the right place. Check your
%APP_ROOT/config/environment.rb
file, and make sure your gem is included there.Also, make sure you've included any necessary resources in your helper. Install instructions for the gem should explain any/all things you need to check to make sure it's setup correctly.