6

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

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

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

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

宝石

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

记录.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

路线.rb

  resources :records do
    get :autocomplete_artist_name, :on => :collection
  end

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

https://gist.github.com/1137340

4

2 回答 2

3
  • 在中添加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 而不是路径方法

    form do |f|
      f.input :artist_name, :as => :autocomplete, :url => '/admin/records/autocomplete_artist_name'
      f.buttons
    end
    
  • 安装 jquery css 使自动完成建议框看起来不错。看到这个帖子。然后编辑app/assets/stylesheets/active_admin.css.scss以包含 jquery-ui css

于 2011-12-24T10:18:24.623 回答
1

表单块在 ActiveAdmins DSL 范围内执行。

尝试以部分形式呈现表单以访问 url 帮助程序。

ActiveAdmin.register Post do
   form :partial => "form"
end

http://activeadmin.info/docs/5-forms.html

于 2011-11-01T23:44:12.927 回答