active_admin 自动完成与rails3-jquery-autocomplete gem

发布于 2024-12-12 14:13:01 字数 1263 浏览 1 评论 0原文

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

我正在使用最新版本的 active_admin< /a> (来自 git)现在依赖于 formattastic 2,我正在使用 1.04 的 rails3-jquery-autocomplete

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

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

gemsrecords.rb

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

(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

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

https://gist.github.com/1137340

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盗梦空间 2024-12-19 14:13:01
  • routes.rb中添加了admin命名空间

    # 将此行放在 ActiveAdmin.routes 之上。否则,您可能会收到此错误
    # ActiveRecord::RecordNotFound(无法找到 id=autocomplete_artist_name 的记录):
    命名空间:admin 做
      资源:记录做
        获取 :autocomplete_artist_name, :on => :收藏
      结尾
    结尾
    
    ActiveAdmin.routes(自身)
    
  • app/assets/javascript/active_admin.js

    //=需要jquery
    //= 需要 jquery_ujs
    //= 需要 jquery-ui
    //= 需要自动完成轨道
    

  • app/admin/records.rb 中,我的解决方法是在字符串中使用 url 而不是路径方法

    形成 |f|
      f.input :艺术家姓名, :as => :自动完成,:url => '/admin/records/autocomplete_artist_name'
      f.按钮
    结尾
    
  • 安装了jquery css以使自动完成建议框看起来不错。请参阅此帖子。然后编辑 app/assets/stylesheets/active_admin.css.scss 以包含 jquery-ui css

  • 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

执笔绘流年 2024-12-19 14:13:01

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

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文