Opt In Features
Opt In Features
Sometimes you may want to keep a feature hidden from the user until they opt in to it. This can be useful for features that are still in beta, or for features that are not yet ready for general use.
For this, LoopOS UI provides a simple way render a feature only if the user has manually opted in.
This is achieved using a the LooposUi::Middleware::OptInFeatures middleware, with additional helper methods that are available in the views.
Usage
Declare the feature flag in the lib/loopos_ui/middleware/opt_in_features.rb file.
# ... FLAGS = { new_tables: true # default value your_feature_flag: false # default value }# ...The default value will be set if the feature flag is not present in the query parameters.
Helpers become available in the view to check if the user has opted in to a feature:
# some view file<%= if lui_use_your_feature_flag? %%> <%%= render LooposUi::SomeComponent.new %%><% end %%>To enable the feature, the user can pass in the feature flag as a query parameter:
?lui__your_feature_flag=true
This will keep the feature enabled session-wide, until the user logs out, the session expires or the user disables by setting it to false:
?lui__your_feature_flag=false