ActiveAdmin - generate link to index, with filter preset?

jgshurts picture jgshurts · Apr 3, 2012 · Viewed 8.5k times · Source

In an ActiveAdmin page, I would like to include a link to a list of related resources. For example, given that a

  • Site has_many Sections and,
  • Section belongs_to a Site (in my ActiveRecord models),

I would like my Site's show page to include a link to Sections within the site, which would go to the Section index page, with the Site filter preset.

Note that

  • I do not want to use ActiveAdmin's belongs_to function;
  • I don't want nested resources for a number of reasons (depth of nesting > 2, as well as usability concerns).

What I want is to generate a URL similar to the one ActiveAdmin generates if I first go to the Sections index page and then filter by Site.

The query parameter list generated by ActiveAdmin's filtering feature is pretty crazy; is there a helper method I could use to achieve this goal?

Thanks!

Answer

Dorian picture Dorian · Sep 19, 2014

I use this syntax:

link_to "Section", admin_sections_path(q: { site_id_eq: site.id })