【发布时间】:2012-10-16 19:08:50
【问题描述】:
我正在学习本教程 [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'
【问题讨论】:
-
更新路由后是否重启了网络服务器?
标签: ruby-on-rails gem jquery-autocomplete