简体   繁体   English

如何在ActiveAdmin菜单或标题中添加输入搜索字段

[英]How do you add an input search field in an ActiveAdmin menu or header

I am trying to add a search field into the ActiveAdmin header. 我正在尝试将搜索字段添加到ActiveAdmin标头中。 I would prefer it to be next to the logout button in ActiveAdmin, but I'd settle for it being anywhere in the header. 我希望它位于ActiveAdmin中的注销按钮旁边,但我会希望它位于标题中的任何位置。 I've tried using admin.build_menu with no luck. 我试过使用admin.build_menu ,但没有运气。 I don't want to use sidebars since it would eat into my horizontal space. 我不想使用侧边栏,因为它会占用我的水平空间。

It would be great to be able to do something like this: 能够做这样的事情很棒:

config.namespace :admin do |admin|
  admin.build_menu do |menu|
    menu.add :input => 'Search', :url => "/search"
  end
end

and have it place a search box in the menu bar 并将其放置在菜单栏中的搜索框

Any help on this would be appreciated. 任何帮助,将不胜感激。 I'd like to do this as cleanly as possible without overriding ActiveAdmin code, but I'm willing to entertain any solution. 我想在不覆盖ActiveAdmin代码的情况下尽可能干净地执行此操作,但是我愿意接受任何解决方案。

The solution I implemented is via jQuery. 我实现的解决方案是通过jQuery。 Added this line on active_admin.js: 在active_admin.js上添加了以下行:

$('#header ul#tabs').append('<li><input id="listing-search" type="text" placeholder="Listing Number"></input></li>');

Then handle the event correspondingly (via JS of course). 然后相应地处理事件(当然通过JS)。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM