So, this is deprecated, but I needed to conditionally hide the edit / destroy buttons on both the index page and the display page, and although this helped me a lot, I felt that a more complete answer could help others faster.
Assume a go ...
Conditionally show links to the index
It's relatively simple, just do not include βactionsβ and instead include your own:
index do id_column column :name column :foo column :bar column :funded
Conditional display of buttons when displaying
Here we need to remove all the default buttons from the display page, and then add the necessary buttons:
# Remove the buttons from the show page config.action_items.delete_if { |item| item.display_on?(:show) } # Then add in our own conditional Edit Button # (note: 'loan' is the registered model name) action_item :edit, only: [ :show ] , if: proc { !loan.funded? } do link_to "#{I18n.t('active_admin.edit')} Loan", edit_resource_path(resource) end # and our Delete Button action_item :delete, only: [ :show ] , if: proc { !loan.funded? } do link_to "#{I18n.t('active_admin.delete')} Loan", resource_path(resource), method: :delete, confirm: I18n.t('active_admin.delete_confirmation') end # and our (custom) Fund Loan Button action_item :fund_loan, only: [ :show ], if: proc { !loan.funded? } do link_to 'Fund Loan', fund_loan_admin_loan_path(loan), method: :patch end # our custom actions code member_action :fund_loan, method: :patch do if resource.fund redirect_to resource_path(resource), notice: 'Loan funded' else redirect_to resource_path(resource), alert: "Loan funding failed : #{resource.errors.full_messages}" end end
Hope this helps someone who stumbled upon this page. Happy coding =]
source share