Antarr Byrd
Antarr Byrd

Reputation: 26061

How to show edit link only in show view using ActiveAdmin

I want to show the link in the show view of ActiveAdmin. But it should not show up in the grid of the index view. I can't figure out how to do this. I've already tried quite a few approaches.

attempt 1

actions :all, except: proc{ params['id'].present? ? [:new, :destroy] : [:new, :destroy, :edit] }.call

this fails with undefined local variable or method 'params'

attempt 2

  actions :all, only: :show, except: [:new, :destroy, :edit]
  action_item only: :show do
    link_to 'Edit Cash Out', "/admin/documents/#{params['id']}/edit" if params['id']
  end

this fails because the route isn't being created for the edit path

attempt 3

  actions :all, except: [:new, :destroy].tap do |a|
    a << :edit unless params['id'].present?
  end

fails with no block given

Upvotes: 0

Views: 1048

Answers (2)

Vishal
Vishal

Reputation: 7361

Can you please try below code?

actions :all, only: :show, except: [:new, :destroy, :edit]

action_item :view, only: :show do
  link_to 'Edit Cash Out', "/admin/documents/#{params['id']}/edit" if params['id']
end

Upvotes: 2

Violeta
Violeta

Reputation: 710

If I am not mistaken, you only want to hide the link to the edit action in the index page (in the grid).

If this is correct, one possible solution is included in this answer:

possible solution

index do
  column :actions do |item|
    links = []
    links << link_to('Show', show_item_path)
    links << link_to('Delete', delete_item_path, method: :delete, confirm: 'Are you sure?')
    links.join(' ').html_safe
  end
end

Just keep in mind to adjust the aforementioned code to fit the routes and naming.

Hope this works for you.

Upvotes: 2

Related Questions