Reputation: 13591
I'm having an issue using the rails3-jquery-autocomplete gem with active_admin
I'm using the most recent version of active_admin (from git) which now relies on formtastic 2 and I'm using 1.04 of rails3-jquery-autocomplete
undefined local variable or method `autocomplete_artist_name_records_path' for #<ActiveAdmin::DSL:0x007fde797140d0>
It doesn't like the url route I'm providing, any ideas what I could be doing wrong?
gem 'activeadmin', :git => 'git://github.com/gregbell/active_admin.git'
gem 'rails3-jquery-autocomplete', '~> 1.0.4'
ActiveAdmin.register Record do
#...
controller do
autocomplete :artist, :name#, :full => true
end
form do |f|
f.input :artist_name, :as => :autocomplete, :url => autocomplete_artist_name_records_path
end
end
resources :records do
get :autocomplete_artist_name, :on => :collection
end
I also tried this fix which I found somewhere but it didn't change anything including the error
https://gist.github.com/1137340
Upvotes: 6
Views: 4115
Reputation: 2621
Added admin
namespace in routes.rb
# Put this line above ActiveAdmin.routes. Otherwise, you may get this error
# ActiveRecord::RecordNotFound (Couldn't find Record with id=autocomplete_artist_name):
namespace :admin do
resources :records do
get :autocomplete_artist_name, :on => :collection
end
end
ActiveAdmin.routes(self)
Added these lines in app/assets/javascript/active_admin.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
In app/admin/records.rb
, my workaround is using url in string instead of path method
form do |f|
f.input :artist_name, :as => :autocomplete, :url => '/admin/records/autocomplete_artist_name'
f.buttons
end
Installed jquery css to make the autocomplete suggestion box look nice. See this post. Then edit app/assets/stylesheets/active_admin.css.scss
to include the jquery-ui css
Upvotes: 3
Reputation: 1297
The form block is being executed in the scope of ActiveAdmins DSL.
Try rendering the form in a partial to access url helpers.
ActiveAdmin.register Post do
form :partial => "form"
end
http://activeadmin.info/docs/5-forms.html
Upvotes: 1