سؤال

I'm using Activeadmin for the admin interface on an app I'm working on (loving it) and I am curious if there is a way to disable the "New Resource" link in the upper-right corner of the resource show page?

The particular resource I'm using is nested inside another resource and I have a partial that allows it to be created from the show page on that parent resource.

I have disabled the resource in the menu, but I'd rather leave the resource in the menu so I can see/edit/delete those resources without having to find it by looking through its parent resource.

هل كانت مفيدة؟

المحلول

Try config.clear_action_items!

نصائح أخرى

Previous solution didn`t work for me, so here is general solutions, that works always:

ActiveAdmin.register Book do
  actions :index

  #or like that
  #actions :all, :except => [:destroy]

  index do
    column :title
    column :author
  end  
end

This removed the "New Resource" button from the top-right:

    config.clear_action_items!

This removed both the "New Resource" button as well as the box "There are no resources yet - create one".

    actions :all, :except => [:new]

Thank you, Irio

I know this is an old question, but I just came up to it (had the same problem), and realized that config.clear_action_items! and actions :all, :except => [:new] are fundamentally different.

config.clear_action_items! will remove the New button from the index page, while actions :all, :except => [:new] will remove both the button, AND the route, meaning you can't call it from another place (which, in my case, is needed).

config.clear_action_items!

Will remove all the actions. If you only want to remove the new action link you can also use:

config.remove_action_item(:new)

I did this:

controller do
  def action_methods
    if some_condition
      super
    else
      super - ['new', 'create', 'destroy']
    end
  end
end

To disable some of the possible actions. action_methods returns an array of the 7 standard CRUD actions, so you can subtract those you don’t want

Or even:

ActiveAdmin.register Purchase do
  config.clear_action_items!
  actions :index
end
Worked for me too ! :-) 

ActiveAdmin.register AssetSumView do
             menu :label => "Asset Summary View", :parent => "Things"
# no button for NEW (since this is a db view)
#---------------------------------------------------------------------------------------------
config.clear_action_items!

    enter code here

   action_item do
      link_to "Assets" , "/admin/assets" 
    end

   action_item do
      link_to "AssetCatgCodes", "/admin/asset_catg_codes"
    end

#---------------------------------------------------------------------------------------------
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top