Here you can find a list of helper methods that are available in the Admin Dashboard that you can use in every template.
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:
Custom text to display in the badge. If not provided, will show “Active”/“Inactive” based on the condition.
active_link_to_with_icon
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.
will return
current_store
Store name
Example: “My Store”
Store URL
Example: https://mystore.com
Unique store identifier
Example: my-store
Default store currency
Example: USD
List of supported currencies
Example: USD,EUR,GBP
Default store locale
Example: en
List of supported locales
Example: en,es,fr
Default country ID
Example: 1
Default country Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
Checkout zone ID
Example: 2
SEO title
Example: My Amazing Store
Meta description for SEO
Example: The best products at the best prices
Returns the current store Spree::Store instance.
current_vendor
Unique vendor identifier
Example: 1
Vendor name
Example: “My Vendor”
Vendor state/status
Example: active
icon
Displays an icon.
Will render
< i class = "ti ti-eye" ></ i >
We use Tabler Icons library for icons.
You can also pass additional options such as:
Add additional CSS classes to the icon
Add additional inline styles to the icon
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 .
link_to_with_icon
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
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? %>