Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 624
holden Avatar asked Oct 29 '11 15:10

holden


2 Answers

  • 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

like image 64
chifung7 Avatar answered Oct 19 '22 09:10

chifung7


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

like image 22
Christos Avatar answered Oct 19 '22 11:10

Christos