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.
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_to
s 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With