Creating a global search feature

229 views
Skip to first unread message

Walksalong

unread,
Mar 5, 2012, 2:00:36 PM3/5/12
to rails_admin
Hello,

I'm trying to add a global search on all of the models using Sunspot.
Is there a way to add this action to the dashboard or would I have to
create a Search model and have a custom action within it as a tab?

Many thanks

Benoit Bénézech

unread,
Mar 6, 2012, 4:52:49 AM3/6/12
to rails...@googlegroups.com
Add a custom action on the root level.
Maybe augment the action API to get a search field in the Bootstrap's upper bar. (instead of a link to the action)

Walksalong

unread,
Mar 6, 2012, 11:35:44 AM3/6/12
to rails...@googlegroups.com
Thanks Benoit I'm somewhat of a newbie. I created a custom action using the script described in the wiki, but I'm unsure how to connect everything so it displays on the root level. 

rails
plugin new rails_admin_search
in routes.rb
mount RailsAdminSearch::Engine => '/search', :as => 'rails_admin_search'
in RailsAdminSearch.rb
    RailsAdmin::Config::Actions.register(self)
      register_instance_option :root do
    true
    end
I imagine there are additional steps I'm missing.
Thanks!

Walksalong

unread,
Mar 6, 2012, 3:42:09 PM3/6/12
to rails...@googlegroups.com
Nevermind I figured it out.. a lil slow over here. 

  config.actions do
    # root actions
    root :search, :dashboard
  end

Walksalong

unread,
Mar 13, 2012, 3:09:27 PM3/13/12
to rails...@googlegroups.com
I'm back working on the search and was wondering where do the controller methods go within the custom action? When I use the form what would be the path to call those controller methods?

Benoit Bénézech

unread,
Mar 14, 2012, 8:41:08 AM3/14/12
to rails...@googlegroups.com
You can't set controller actions in custom actions.

Only a block evaluated in a controller action generated for you (name is the name of the action unless overriden).

You can off course add any action instance options and methods you want.

In the form, use #controller to access the controller. (spaghetti code smell, though)
Reply all
Reply to author
Forward
0 new messages