Wednesday, February 26, 2014

Using table_for with HTML elements in Active Admin

Ah yes another foray into ActiveAdmin. Recently I needed to use the table_for feature on a show page and add some html options to it. This required looking into the code itself as the documentation was not exactly clear in either ActiveAdmin or Arbre. Essentially you need to do something like this:
    table_for agent.quotes, {:id => 'agent_quotes'} do
      column 'Quote Number' do |quote|
        quote.slug
      end
      column 'Business' do |quote|
        quote.business.name
      end
      column 'Status' do |quote|
        quote.state
      end
      column '' do |quote|
        link_to 'View Quote', admin_quote_path(quote.id)
      end
    end
It was as simple as adding a hash with the needed items after the collection for the table_for:
table_for collection, {:id => 'html_id', :class => 'html_class'}