Reputation: 21
I am following this tutorial [https://github.com/crowdint/rails3-jquery-autocomplete][1], but I'm having problems.
My models:
class Category < ActiveRecord::Base
attr_accessible :name
has_many :products
end
class Product < ActiveRecord::Base
attr_accessible :name, :category_id
belongs_to :category
end
Schema:
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
Here is my controller:
autocomplete :category, :name
My layout has this:
<%= javascript_include_tag :defaults, "autocomplete-rails.js" %>
My routes has this:
resources :products do
get :autocomplete_category_name, :on => :collection
end
And my form has this:
<%= f.autocomplete_field :category_name, autocomplete_category_name_products_path %>
I have the autocomplete-rails.js in my app/assets/javascript folder. Yet for some reason I keep getting this error:
undefined method `category_name'
Upvotes: 2
Views: 892
Reputation: 821
You should use
<%= f.autocomplete_field :category, autocomplete_category_name_products_path, :id_element => '#product_category_id' %>
<%= f.hidden_field :category_id %>
Upvotes: 1
Reputation: 14943
Make sure you have the gem installed and bundled then restart the server again
gem 'rails3-jquery-autocomplete`
Upvotes: 0