%= lato_page_head "Documentation" %>
lato_settings adds an application settings section to a Lato admin panel.
Use it when admins need to edit values such as site name, feature flags, limits, labels,
dates, or other configuration values without changing code.
Add Lato Settings to the application Gemfile:
gem "lato"
gem "lato_settings"
Install the engine and run migrations:
bundle
rails lato_settings:install:application
rails lato_settings:install:migrations
rails db:migrate
Mount the engine in config/routes.rb:
Rails.application.routes.draw do
mount LatoSettings::Engine => "/lato-settings"
# ...
end
Import styles in app/assets/stylesheets/application.scss:
@import "lato_settings/application";
Import JavaScript in app/javascript/application.js:
import "lato_settings/application"
Users must be logged into Lato and must have Lato Settings admin permission enabled.
user = Lato::User.find_by(email: "admin@example.com")
user.update!(lato_settings_admin: true)
Read values with LatoSettings.get(key, default = nil).
If the setting does not exist, the method returns the default value.
site_name = LatoSettings.get("site_name", "Default site")
items_per_page = LatoSettings.get("items_per_page", 25)
launch_date = LatoSettings.get("launch_date")
Prefer LatoSettings.get in new code.
| Type | Use for |
|---|---|
string |
Short text values. |
text |
Long text values. |
integer |
Whole numbers. |
number |
Decimal numbers. |
date |
Date values. |
select |
One value chosen from a list. |
Create important settings in seeds, then let admins edit values from the panel. Mark a setting as required when it must not be deleted from the UI.
LatoSettings::Setting.find_or_create_by!(key: "site_name") do |setting|
setting.value = "My application"
setting.label = "Site name"
setting.description = "Name shown in public pages"
setting.typology = :string
setting.required = true
end
Use clear lowercase keys with underscores, such as site_name, items_per_page, or launch_date.