gpt4 book ai didi

ruby-on-rails - 使用 rails3-jquery-autocomplete gem 自动完成 active_admin

转载 作者:行者123 更新时间:2023-12-04 15:26:04 25 4
gpt4 key购买 nike

我在使用带有 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
  • 关于ruby-on-rails - 使用 rails3-jquery-autocomplete gem 自动完成 active_admin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7939800/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com