Skip to content

Administrate has deprecated valid_action? #48

Closed

Description

@johncip

Issue

Using administrate_exportable with administrate v0.18.0 will cause a deprecation warning to get logged in test and development. They look like this:

DEPRECATION WARNING: The method `valid_action?` is deprecated. Please use `accessible_action?`
instead, or see the documentation for other options. (called from valid_action?
at <GEM_PATH>/administrate-0.18.0/app/controllers/administrate/application_controller.rb:125)

Apparently the practice of calling valid_action? and show_action? was replaced with a single call to a new method, accessible_action? in this PR: thoughtbot/administrate#1941

As far as I can tell, that PR is part of administrate v0.18.0, and unfortunately accessible_action? doesn't exist in versions before v0.18.0.

I'm guessing that making the deprecation warning go away at the cost of breaking compatibility with older versions isn't worth it, and neither is making the behavior conditional on e.g. Gem.loaded_specs["administrate"].version ... but I thought I'd make this issue for documentation value at least.

Workaround

The change, were it made, would result in the export button's link_to in app/views/admin/application/_index_header.html.erb becoming:

    <%= link_to(
      'Export',
      [:export, namespace, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
      class: 'button',
      target: '_blank'
    ) if accessible_action?(page.resource_name, :export) %>

Folks using the latest administrate who wish to avoid the warning can simply copy administrate_exportable's version of _index_header.html.erb into their project, and update the export button's link_to to the above. (Generating views in administrate didn't spit out the file when I tried it.)

Finally, it might be of some use to update the readme to provide both versions -- @andreibondarev I'm happy to make a PR with whatever change is desired, if a change is desired at all.

Activity

  1. pablobm commented on Mar 8, 2024

    @pablobm

    Hello 👋 Deprecator of valid_action? here. Sorry about the change! A back-compatible option might be to do the following:

    1. Substitute valid_action? with existing_action?.
    2. Use metaprogramming to detect the existence of existing_action?.
      • If it doesn't exist, add your own implementation based on valid_action?. (This will support older versions).
    3. Silence the warning by overriding Administrate.warn_of_deprecated_authorization_method.

    But none of this is supported, and generally it's recommended to use accessible_action?.

  2. johncip commented on Oct 29, 2025

    @johncip
    Author

    Slight tweak to my workaround code, which won't work if the model has a name that is already plural (e.g. UserSettings).

    In those cases, rails has to disambiguate on collection routes, so you will have something like "export_admin_user_settings_index_path" (where the "_index" doesn't appear on models with singular names).

    Something like this should work everywhere, though I haven't tested it heavily:

    <%= link_to(
      'Export',
      polymorphic_path(
        [:export, namespace, page.resource_name.to_s.classify.constantize],
        sanitized_order_params(page, :id).to_h.merge(format: :csv)
      ),
      class: 'button',
      target: '_blank'
    ) if accessible_action?(page.resource_name, :export) %>
    
  3. andreibondarev commented on Oct 21, 2026

    @andreibondarev
    Member

    This is addressed in #59 and will close automatically when it's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions