administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Custom additional action on actions column on index page

Open bekicot opened this issue 5 years ago • 5 comments

  • What would you like to be able to do? Can you provide some examples? Custom additional action on actions column on the index page

  • How could we go about implementing that? The simplest way is to move the actions column into partial so that the user can override just the actions column part of the table. Instead of overriding the whole collection partial. We also need to update the column heading count to also account for the additional custom action.

Another approach is probably to add ability to add an action button via the dashboard class.

# CarDashboard.rb
ACTIONS = [:start, :stop, :destroy, :show]
# CarController.rb
def start
resource.start!
end
  • Can you think of other approaches to the problem? Currently, we can override the whole collection partial. But it will lead to a greater incompatibility upon updating administrate.

bekicot avatar Jun 15 '20 23:06 bekicot

I'd prefer two partials: one for the header and another for the record rows, both used from app/views/administrate/application/_collection.html.erb. At least for now, as it will be more forward-compatible. In the future, this may or may not be generated from external info (such as new dashboard field like the one you propose), but for now I feel that would add unnecessary complexity.

How do you feel about this? Would you be able to create a PR that splits the two partials out of that template?

pablobm avatar Jun 25 '20 08:06 pablobm

@pablobm I will find some time this weekend to tackle this one. Please assign this issue to me.

bekicot avatar Jul 09 '20 00:07 bekicot

Is there any progress on this? I am trying to add a custom action link to my dashboard and having issues with it.

This is my route:

get 'admin/foo/:id/solr_index', to: 'foo#solr_index', as: 'admin_foo_solr_index_path'

I am adding this link_to to my _collection.html.erb file for foo controller:

<%= link_to(
            t("administrate.actions.solr_index"),
            [namespace, resource, :solr_index]

            ) if show_action? :solr_index, resource %>

And I am getting the following error on the index page:

Showing /xxx/app/views/admin/foo/_collection.html.erb where line #87 raised:

undefined method `admin_foo_solr_index_path' for #<#<Class:0x007fcce47c8720>:0x007fcce4adcd80>

I would appreciate if you could tell me what I am missing here.

audyaver avatar Jul 28 '21 20:07 audyaver

@audyaver - In your specific case, I think that Administrate is not the problem. Your route definition looks wrong. You have this:

get 'admin/foo/:id/solr_index', to: 'foo#solr_index', as: 'admin_foo_solr_index_path'

And I think it should be this:

get 'admin/foo/:id/solr_index', to: 'foo#solr_index', as: 'admin_foo_solr_index'

To clarify: without the suffix "_path", as this is added automatically by Rails. In your example, you'd get the route helpers admin_foo_solr_index_path_path and admin_foo_solr_index_path_url, which I don't think is what you want.

pablobm avatar Aug 08 '21 05:08 pablobm

Re: this issue in general, there's some progress at https://github.com/thoughtbot/administrate/pull/1998, which implements new partials to help with this.

pablobm avatar Aug 08 '21 05:08 pablobm

This should be fixed now after merging https://github.com/thoughtbot/administrate/pull/1998. I have added it to the list of stuff to document.

pablobm avatar Apr 06 '23 12:04 pablobm