Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the breadcrumbs while using Active Admin gem in Rails?

I have been using Active admin gem and want to remove the breadcrumbs from Admin dashboard. To achieve this I referred this blog to customize TitleBar.

I did following steps:

  1. Created my own class MyTitleBar and copied content of TitleBar class from active_admin/views/title_bar.rb.
  2. Removed build_breadcrumb line in method build_titlebar_left.
  3. Removed whole method build_breadcrumb.
  4. Updated active admin config as:

    config.view_factory.title_bar = MyTitleBar

This works fine.

My Questions:

  1. Is this the right way to achieve above task?
  2. Also, is there any way to remove breadcrumbs model-wise?
like image 288
NSS Avatar asked Dec 25 '22 14:12

NSS


1 Answers

While that solution may work, it's certainly less than ideal. I noticed looking at the ActiveAdmin gem that their is a configuration option for breadcrumb:

ActiveAdmin.register Post do

  breadcrumb do
    [
      link_to('my piece', '/my/link/to/piece')
    ]
  end
end

It looks like it takes a code block, which is returned to a links variable. Looking at TitleBar::build_breadcrumb, if this configuration option isn't defined, it just sets links to the result of breadcrumb_links(). Finally, if some type of links array is there, it formats it for printing. Otherwise, the method returns nothing.

So to solve your problem, try writing a code block that returns nil or an empty. I haven't tested this, but something along the lines of the code block below. The idea is that if you feed the variable nil, it should not pass the links.present? test and should return immediately, not building the undesired breadcrumb HTML. Alternatively an empty array should fit the type it expects, but without any items nothing should be displayed. I'd need to test locally to see which works better on the frontend.

/config/initializers/active_admin.rb:

# Return a Proc that simply returns an empty array
config.breadcrumb = Proc.new{ [] }
like image 119
omgitsfletch Avatar answered Dec 28 '22 08:12

omgitsfletch