简体   繁体   中英

active_admin autocomplete with rails3-jquery-autocomplete gem

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?

gems

gem 'activeadmin', :git => 'git://github.com/gregbell/active_admin.git'
gem 'rails3-jquery-autocomplete', '~> 1.0.4'

records.rb (active_admin)

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

routes.rb

  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

  • 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM