Following along with <https://guides.solidus.io/ad...
# support
t
Following along with https://guides.solidus.io/advanced-solidus/promotions-system/#implementing-a-new-action, I'm running into
uninitialized constant Spree::PromotionAction
. This code worked in a Rails 6 app, but this one's on Rails 7 so maybe this has to do with Zeitwerk. Seems like any initializer which tries to access anything in
Spree::
throws an error. Tried surrounding with a
to_prepare
and
spree.config
but no luck.
Copy code
require "./app/models/embold/promotion/actions/free_product.rb"

Rails.application.config.spree.promotions.actions << "Embold::Promotion::Actions::FreeProduct"
and the line of
free_product.rb
that it's complaining about:
Copy code
module Embold
  module Promotion
    module Actions
      class FreeProduct < ::Spree::PromotionAction
j
Remove the
require
. You're trying to require an autoloaded constant.
The reason the config takes the name of the promo action as a string is that so it doesn't need to be loaded when that line runs (and so that it can be resolved with the correct autoloaded constant when it is actually needed.)
t
Dang the server starts now. I swear I added that because I was getting an error that Embold was undefined but maybe I had some files/directories named wrong.
Thanks! Been staring at this too long I guess. 😅
sg horns 1