-
Notifications
You must be signed in to change notification settings - Fork 32
Boolean
Vinicius Stock edited this page Feb 19, 2019
·
3 revisions
Sail.set(:my_setting, true)
Sail.set(:my_setting, "true")
Sail.get(:my_setting)
=> true
Sail.get(:my_setting) do |setting_value|
puts setting_value
end
=> true
Boolean settings are typically used as feature flags. They can be used to enable or disable some functionality or to hide a portion of screen, for instance. This makes it a good fit for testing new functionality in a controlled way.
In the following example, a notifier system has just been deployed for users and a Boolean setting is being used to enable or disable this new functionality.
# app/models/user.rb
class User < ApplicationRecord
.
.
def notify
Notifier.new(self).deliver if Sail.get(:enable_notifier)
end
end
This second scenario uses a Boolean setting to decide which template partial to render.
# app/views/notifications/index.html.erb
<div>
<% if Sail.get(:use_notifications_v2) %>
<%= render(partial: 'notifications/index_v2' %>
<% else %>
<%= render(partial: 'notifications/index_v1' %>
<% end %>
</div>