ruby on rails - remove delete link only in activeadmin show page -
i working on active admin gem. want hide delete link only show page. so, added below code
activeadmin.register articlesskill menu :parent => "readup" actions :index, :show, :new, :create, :update, :edit index column :name, sortable: :name column :description column "" |resource| links = ''.html_safe links += link_to i18n.t('active_admin.view'), resource_path(resource), :class => "member_link edit_link" links += link_to i18n.t('active_admin.edit'), edit_resource_path(resource), :class => "member_link edit_link" if article.where(articles_skill_id: resource.id).blank? links += link_to i18n.t('active_admin.delete'), resource_path(resource), :method => :delete, :confirm => i18n.t('active_admin.delete_confirmation'), :class => "member_link delete_link" else # links += link_to i18n.t('active_admin.delete'), "#", :confirm => ("this skill has related article. can't delete now"), :class => "member_link delete_link" links += link_to i18n.t('active_admin.delete'), resource_path(resource), :method => :delete, :confirm => i18n.t('active_admin.delete_confirmation'), :class => "member_link delete_link" end links end end end
this removing delete link show page, in index page if try delete record, showing error,
the action 'destroy' not found admin::articlesskillscontroller
any 1 can me in this? please.
so old, found myself needing conditionally hide edit/destroy buttons on both index page , show page, , while helped me lot, felt more complete answer might others quicker.
let's give go...
conditionally show links on index
this 1 relatively straightforward, don't include "actions" , instead include own:
index id_column column :name column :foo column :bar column :funded # don't # actions # instead make our own column, no name looks aa column "" |resource| links = ''.html_safe links += link_to i18n.t('active_admin.view'), resource_path(resource), class: "member_link show_link" if !resource.funded? links += link_to i18n.t('active_admin.edit'), edit_resource_path(resource), class: "member_link edit_link" links += link_to i18n.t('active_admin.delete'), resource_path(resource), method: :delete, confirm: i18n.t('active_admin.delete_confirmation'), class: "member_link delete_link" end links end end
conditionally show buttons on show
here we'll have remove default buttons show page , add in buttons want:
# remove buttons show page config.action_items.delete_if { |item| item.display_on?(:show) } # add in our own conditional edit button # (note: 'loan' registered model's name) action_item :edit, only: [ :show ] , if: proc { !loan.funded? } link_to "#{i18n.t('active_admin.edit')} loan", edit_resource_path(resource) end # , our delete button action_item :delete, only: [ :show ] , if: proc { !loan.funded? } link_to "#{i18n.t('active_admin.delete')} loan", resource_path(resource), method: :delete, confirm: i18n.t('active_admin.delete_confirmation') end # , our (custom) fund loan button action_item :fund_loan, only: [ :show ], if: proc { !loan.funded? } link_to 'fund loan', fund_loan_admin_loan_path(loan), method: :patch end # our custom actions code member_action :fund_loan, method: :patch 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
hopefully helps out stumbles upon page. happy coding =]
Comments
Post a Comment