I am trying to implement an autocomplete form in my rails application.
So far I have gone through the following installation steps.
gem 'jquery-rails' gem 'jquery-ui-rails' gem 'rails4-autocomplete'
//= require jquery //= require jquery_ujs //= require jquery-ui/autocomplete //= require autocomplete-rails
In my models, I have a Job and a Company. A
Job belongs_to Company and a
Company has_many Jobs.
In my routes.rb I have:
resources :companies resources :jobs do get :autocomplete_company_name, :on => :collection end
Jobs controller added to top:
autocomplete :company, :name
All a Job consists of is a Date, and then foreign keys to tables such as Company, Contact, Jobsite, etc. On the Jobs new _form I have:
<%= form_for(@job) do |f| %> <%= f.hidden_field :date, :value=>Time.now %> <%= f.hidden_field :user_id, :value=>current_user.id %> <%= f.fields_for :company, @company do |company| %> <%= company.autocomplete_field :name, autocomplete_company_name_jobs_path %>
I am able to render the autocomplete field on my form, but when i start typing, nothing comes up. Home Depot is one of my dummy companies in my test database, but you can see when i type "Ho" nothing appears to autocomplete.
The page source for the autocomplete field i am rendering appears like so:
<input data-autocomplete="/jobs/autocomplete_company_name" type="text" name="job[company][name]" id="job_company_name" />
I have been following the documentation and instructions found here: https://github.com/bigtunacan/rails-jquery-autocomplete