Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can action buttons be added to dashboard table on activeadmin?

I have this code that creates a table on the activeadmin Dashboard:

columns do 
  column do
    panel "New Mentor's requests" do
      table_for User.where(mentor_request: true) do |t|
        t.column("Id") { |user| user.id }
        t.column("Name") { |user| user.account.full_name }
        t.column("Email") { |user| user.account.email }
        t.column("Organization") { |user| user.organization.name }

      end

    end
  end
end

Is there a way to add "actions" like on the rest of the resources? I mean like "new, edit, delete", but a custom one.

I tried putting the "actions" tag, but I get an undefined method.

like image 930
Nick L Scott Avatar asked Apr 04 '16 20:04

Nick L Scott


2 Answers

table_for is used to render a collection of objects which may not necessarily be ActiveRecord objects, so the action methods aren't available like they are in an index action. However, you should be able to render your own actions with something like this:

column("View User") { |user| link_to "View", user_path(user) }

EDIT For multiple links you can wrap the link_tos use Arbre's span tag:

column("View User") do |user|
  span link_to "View", "/mypath"
  span link_to "Edit", "/mypath"
  span link_to "Delete", "/mypath"
end

I'm using ActiveAdmin 1.0.0.pre2 w/ arbre 1.0.2, I haven't tried it on earlier versions.

like image 125
Anthony E Avatar answered Sep 22 '22 23:09

Anthony E


You can also try this:

ActiveAdmin.register Foo do
  actions :all
  index do
    column :name
    actions defaults: true do |foo|
      link_to "Custom ACTION", custom_action_path(foo.id)
    end
  end
end

It worked for me to have more options than the already defined ones: View, Edit, Delete

Source: https://github.com/activeadmin/activeadmin/issues/53

like image 44
dani24 Avatar answered Sep 24 '22 23:09

dani24