我正在关注本教程 [https://github.com/crowdint/rails3-jquery-autocomplete][1],但我遇到了问题。
我的模型:
class Category < ActiveRecord::Base
attr_accessible :name
has_many :products
end
class Product < ActiveRecord::Base
attr_accessible :name, :category_id
belongs_to :category
end
架构:
create_table "categories", :force => true do |t|
t.string "name"
end
create_table "products", :force => true do |t|
t.string "name"
t.integer "category_id"
end
这是我的控制器:
autocomplete :category, :name
我的布局是这样的:
<%= javascript_include_tag :defaults, "autocomplete-rails.js" %>
我的路线有这个:
resources :products do
get :autocomplete_category_name, :on => :collection
end
我的表格有这个:
<%= f.autocomplete_field :category_name, autocomplete_category_name_products_path %>
我的 app/assets/javascript 文件夹中有 autocomplete-rails.js。但是由于某种原因,我不断收到此错误:
undefined method `category_name'