我在使用带有 active_admin 的 rails3-jquery-autocomplete gem 时遇到问题

我使用的是最新版本的 active_admin (来自 git)现在依赖于 formtastic 2,我使用的是 rails3-jquery-autocomplete 的 1.04

undefined local variable or method `autocomplete_artist_name_records_path' for #<ActiveAdmin::DSL:0x007fde797140d0> 

它不喜欢我提供的 url 路由,知道我可能做错了什么吗?

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

record.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 

路由文件
  resources :records do 
    get :autocomplete_artist_name, :on => :collection 
  end 

我也试过这个我在某处找到的修复程序,但它没有改变任何东西,包括错误

https://gist.github.com/1137340

请您参考如下方法:

  • 已添加 admin 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) 
    
  • app/assets/javascript/active_admin.js 中添加了这些行
    //= require jquery 
    //= require jquery_ujs 
    //= require jquery-ui 
    //= require autocomplete-rails 
    
  • app/admin/records.rb ,我的解决方法是在字符串中使用 url 而不是 path 方法
    form do |f| 
      f.input :artist_name, :as => :autocomplete, :url => '/admin/records/autocomplete_artist_name' 
      f.buttons 
    end 
    
  • 安装了 jquery css 以使自动完成建议框看起来不错。看到这个 post .然后编辑app/assets/stylesheets/active_admin.css.scss包含 jquery-ui css

  • 评论关闭
    IT干货网

    微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!