41

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.

user229044
  • 232,980
  • 40
  • 330
  • 338
YuKagi
  • 2,451
  • 3
  • 21
  • 26

9 Answers9

70

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
makaroni4
  • 2,281
  • 1
  • 18
  • 26
36

Try config.clear_action_items! to remove the link to New and other links on top of the table

Yshmarov
  • 3,450
  • 1
  • 22
  • 41
makvool
  • 392
  • 3
  • 2
28

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

ea0723
  • 805
  • 11
  • 25
  • 2
    Small note here. If you define a custom controller and define `new` inside of the controller block, that will override this setting. Just learned that one. If you specify that a certain action shouldn't exist, ensure you do not also define it in a `controller` block! – danielricecodes Mar 22 '17 at 17:38
13
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)
hcarreras
  • 4,442
  • 2
  • 23
  • 32
9

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).

7

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

jpbalarini
  • 1,082
  • 1
  • 17
  • 23
4

Or even:

ActiveAdmin.register Purchase do
  config.clear_action_items!
  actions :index
end
irio
  • 1,401
  • 14
  • 11
0
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

#---------------------------------------------------------------------------------------------
Balius
  • 9
  • 1
0

config.clear_action_items! does only half of the job. There is one issue though.

In case of empty index table, active admin show this message

There are no [Resources] yet. Create one

which doesn't get hidden by the above command and I don't want to entirely disable the action. So, I kept the link and edited the new action to redirect to the parent resource index with a message.

controller do
  def new
    if params[:parent_id].present?
      super
    else
      redirect_to parent_resources_path, notice: "Create Resource through ParentResource"
    end
  end
end
Magzy
  • 73
  • 9