Blog icon

Wallaby: a newcomer in the admin interface market

By Tianwen Chen,
Tianwen Chen
Scroll down to read

Are you struggling to choose between ActiveAdmin and Rails Admin? Just to confuse you even further, there is a now a third option:

Wallaby

So, apart from an admin interface, what is Wallaby? The core design is that:

  • It uses the decorator to store the customisation information for an ActiveRecord model.
  • It can be customised in a pure Rails way using controllers and views.

How does this work exactly? A piece of code is worth a thousand words! To illustrate, let's use the following ActiveRecord model:

#! app/models/product.rb
class Product < ActiveRecord::Base
  has_one :picture, as: :imageable
  has_many :order_items, class_name: Order::Item.name
  has_many :orders, through: :order_items
  belongs_to :category
  has_and_belongs_to_many :tags

  scope :featured, -> { where(featured: true) }
end

Before we make any changes, let's take a look at the show page:

wallaby - products - before

Now, here comes the customisation:

  • The code snippet below updates the show pages to display only the preview and order fields. preview is a custom field with a custom markdown type.

    #! app/decorators/product_decorator.rb
    class ProductDecorator < Wallaby::ResourceDecorator
      self.show_fields[:preview] = { type: 'markdown', label: 'preview' }
      self.show_field_names = %w( preview orders )
    
      def preview
        "# #{name} - #{sku}\n#{description}"
      end
    end
    
  • To make preview display as custom type markdown, we need to create a type partial as follows:

    <% #! app/views/admin/products/show/_markdown.html.erb %>
    <% markdowner = Redcarpet::Markdown.new(Redcarpet::Render::HTML, {}) %>
    <%= raw markdowner.render value %>
    
  • The following customisation displays a pinned message at the top of show page. It doesn't directly relate to the above example, but it does illustrate how things can be customised at the controller level.

    #! app/controllers/admin/products_controller
    module Admin
      class ProductsController < Wallaby::ResourcesController
        def show
          flash[:warning] ||= "Product import will happen after business hours tonight."
          super
        end
      end
    end
    

Then the show page will become:

wallaby - products - after

The above codes are not the best example, but they make my point. Too simple to believe, isn't it?

Moreover, Wallaby has a lot to offer:

  • It handles all ActiveRecord associations, including polymorphism.
  • It supports Single Table Inheritance (STI)
  • Predefine filters to allow user to easily access the custom query
  • Advanced colon search, e.g., ordered_at:>2017-07-01 name_start_with:^tian
  • User-friendly and responsive UI

Making a great admin interface using Wallaby is just a beginning. Find out more here.

To find out how reinteractive can turn your web application vision into reality, get in touch with us through our contact form or call us on +61 2 8019 7252.