ruby-on-railsactiveadmin

Activeadmin filter : How to use a path as a filter method parameter


I've created a custom formtastic input which take a URL in parameter. It work as expected when the input is used in a view.

But I want to use this custom input in a activeadmin filter. This also work as expected, except when I want to specify the URL param :

This work :

filter :my_field, as: :my_custom_input, url: '/admin/my_models/my_action'

The url parameter is passed to my input and i can use it as usual. But I want to use the standard rails path translation from route. And it doesn't work :

filter :my_field, as: :my_custom_input, url: my_action_admin_my_models_path

This fail because it can't find the "my_action_admin_my_models_path " method. (And i'm sure this method work in views)

I've tried to use a Proc, but it doesn't work too, same error.

How can I do to use a rails route path method in a activeadmin filter ?

Thanks for your help.


Solution

  • I managed to do this using url_helpers in a proc:

    filter :my_field, as: :my_custom_input, url: proc { Rails.application.routes.url_helpers.autocomplete_alert_product_name_admin_claims_path }