Custom additional action on actions column on index page
-
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
collectionpartial. 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
collectionpartial. But it will lead to a greater incompatibility upon updating administrate.
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 I will find some time this weekend to tackle this one. Please assign this issue to me.
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 - 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.
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.
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.