From adc46c31b2b5ba38519461b31cef566217011f20 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 30 Mar 2021 14:44:02 +0200 Subject: [PATCH] Update Guides for Preferences::Persistable These methods aren't available automatically any longer, thanks to Rails 6.1. They actually weren't in the first place, because not every model has a `preferences` column. --- .../preferences/add-model-preferences.html.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/guides/source/developers/preferences/add-model-preferences.html.md b/guides/source/developers/preferences/add-model-preferences.html.md index c85e1cb7722..371c249d08c 100644 --- a/guides/source/developers/preferences/add-model-preferences.html.md +++ b/guides/source/developers/preferences/add-model-preferences.html.md @@ -4,7 +4,13 @@ Solidus comes with many model-specific preferences. They are configured to have default values that are appropriate for typical stores. Additional preferences can be added by your application or included extensions. -Preferences can be set on any model that inherits from [`Spree::Base`][spree-base]. +Preferences can be set on any model that includes `Spree::Preferences::Persistable`. +In core Solidus, these are all classes inheriting from: + + - `Spree::Calculator` + - `Spree::PromotionAction` + - `Spree::PaymentMethod` + - `Spree::PromotionRule` Note that model preferences apply only to the current model. To learn more about application-wide preferences, see the [App configuration][app-configuration] @@ -21,6 +27,7 @@ You can define preferences for a model within the model itself: ```ruby module MyStore class User < Spree::Base + include Spree::Preferences::Persistable preference :hot_salsa, :boolean preference :dark_chocolate, :boolean, default: true preference :color, :string @@ -30,7 +37,7 @@ module MyStore end ``` -This will work because User is a subclass of Spree::Base. If found, +This will work because User includes [`Spree::Preferences::Persistable`][spree-persistable]. If found, the preferences attribute gets serialized into a Hash and merged with the default values.