Skip to main content
Version: v3.0

Super Admin

By default Rhino includes an admin dashboard that allows you to manage your application. This dashboard is built using the ActiveAdmin gem.

Security

ActiveAdmin 3+ requires ransack 4 which has a system for whitelisting attributes and scopes for searching. Rhino by default allows the same attributes and associations for viewing and for filtering as for reading.

To customize the attributes and associations that can be searched, you can override the ransackable_attributes, ransackable_associations, and ransackable_filters methods in your model.

    def ransackable_attributes(_auth_object = nil)
super + ['my_special_attribute']
end

def ransackable_associations(_auth_object = nil)
super + ['my_special_scope']
end

def ransackable_filters(auth_object = nil)
super + ['my_special_filter']
end
end

Dashboard

Rhino uses the ActiveAdmin gem to create an admin dashboard. It is a powerful tool that allows you to create a custom admin dashboard for your application.

By default Rhino comes with a basic dashboard that displays all resources and allows editing based on the configuration.

Configuration

The admin dashboard configuration is in config/initializers/active_admin.rb and can be altered to the project needs.

Extending

When the admin dashboard is generated, it will create a model for each resource. You can override the default behavior by creating a new model in the app/admin folder. For example, if you want to change the default filters for the Blog resource, you can create app/admin/blog.rb:

app/admin/blog.rb
ActiveAdmin.register Blog do
filter :title
filter :published
end

Theming

Rhino includes the arctic_admin theme.

ActiveAdmin Addons

Rhino include the activeadmin_addons gem to add some extra functionality to ActiveAdmin.

Optimizing select filters

ActiveAdmin’s default select filter loads all records from the database which can cause significant performance issues. To avoid this, a lazy typeahead select filter can be created using activeadmin_addons, and the Ransack gem used by ActiveAdmin.

Imagine we have an InvoiceLineItem table, that belongs to a UsersRole, that in turn belongs to a User. If we want a “User“ filter in the InvoiceLineItem Index page, we would do something like this:

app/admin/invoice_line_items.rb
ActiveAdmin.register InvoiceLineItem do
preserve_default_filters!
remove_filter :users_role # remove original filter
filter :users_role_user_id, # this name must contain the relationships path from the model from the index page until the user table, so invoice_line_item -> users_role -> user. the engine will do a join.
label: "User",
as: :search_select_filter,
url: proc { admin_users_path }, # AJAX endpoint
fields: %w[name nickname email], # columns in the looked up table to be compared against
minimum_input_length: 2,
method_model: User, # original table
width: "190px", # necessary for fixing a UI bug
display_name: "full_nickname_and_email", # custom display name that gives you more flexibility to use whatever you want
order_by: "name"
end

Create a json view for the admin_users_path to return a custom attribute that will be shown in the results select box.

app/views/admin/users/index.json.jbuilder
json.array!(@users) do |user|
json.extract! user, :id, :full_nickname_and_email
end

Finish up by implementing the custom display field in the User model:

app/models/user.rb
def full_nickname_and_email
"#{nickname || name} - #{email}"
end
info

jbuilder is no longer included in Rhino by default. You will need to add it to your Gemfile.