Here you can find a list of helper methods that are available in the Admin Dashboard that you can use in every template.

The list is incomplete.

active_badge

Displays a badge with a color based on the condition.

<%= active_badge(order.sent_to_erp_at.blank?) %>

If the condition is true, it will render

<span class="badge badge-success">Active</span>

If the condition is false, it will render

<span class="badge badge-danger">Inactive</span>

You can also pass a custom label to the badge:

label
string

Custom text to display in the badge. If not provided, will show “Active”/“Inactive” based on the condition.

Same as link_to_with_icon, but it will add the active class if the current page is the same as the link.

<%= active_link_to_with_icon 'eye', "View Order in ERP", spree.admin_order_path(order), class: "btn btn-primary" %>

You can also pass a custom active condition.

<%= active_link_to_with_icon 'eye', "View Order in ERP", spree.admin_order_path(order), class: "btn btn-primary", active: order.sent_to_erp_at.blank? %>

currency_select

Available for forms to build a currency select dropdown. Provided via currency_select gem.

<div class="form-group">
  <%= f.label :default_currency, Spree.t(:currency) %>
  <%= f.currency_select :default_currency, preferred_currencies, {}, { data: { controller: 'autocomplete-select' } } %>
</div>

Adding data: { controller: 'autocomplete-select' } will enable the autocomplete feature.

current_currency

Returns the currently selected currency. By default in Admin Dashboard this will be store.default_currency. This can be changed in the Settings -> Store Defaults page.

<%= current_currency %>

will return

USD

current_store

current_store
Spree::Store

Returns the current store Spree::Store instance.

current_vendor

Available only in Spree Enterprise Edition.

current_vendor
Spree::Vendor

icon

Displays an icon.

<%= icon('eye') %>

Will render

<i class="ti ti-eye"></i>

We use Tabler Icons library for icons.

You can also pass additional options such as:

class
string

Add additional CSS classes to the icon

style
string

Add additional inline styles to the icon

height
integer

Set the height of the icon in pixels

<%= icon('eye', class: 'mr-2', height: 20, style: 'color: red;') %>

will render

<i class="ti ti-eye mr-2" style="font-size: 20px; color: red;"></i>

local_time

Displays a time in the user’s timezone in a human readable format (based on the browser’s timezone).

<%= local_time(order.sent_to_erp_at) %>

Provided by local_time gem.

Creates a link with an icon.

<%= link_to_with_icon 'eye', "View Order in ERP", "https://erp.com/orders/#{order.number}", class: "btn btn-primary" %>
  • eye is the icon name.
  • View Order in ERP is the link text.
  • https://erp.com/orders/#{order.number} is the link url. For internal links, please use spree. routes helper, eg. spree.admin_order_path(order).
  • btn btn-primary is the bootstrap class for styling the link

supported_currencies

Returns the list of supported currencies for the current store as an array of strings.

<%= supported_currencies %>

will return

["USD", "EUR"]

try_spree_current_user

Returns the current user object (class depends on the Spree.admin_user_class configuration). If the user is not signed in, it will return nil.

<%= try_spree_current_user.email %>

If you want to check if the user is signed in, you can use the following:

<%= try_spree_current_user.present? %>