-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Discussed in #24
Originally posted by dhnaranjo September 23, 2022
Hello! So I'm trying to do the following:
- keeping Preview files in
app/components/component_name
- building previewed objects using FactoryBot and Faker
- including
FactoryBot::Syntax::Methods
inApplicationViewComponentPreview
so I can callbuild
instead ofFactoryBot.build
- excluding FactoryBot from my Production environment
The result is that when my app directory is eager loaded in Production it gets all upset that FactoryBot::Syntax::Methods doesn't exist. To fix this I put together an initializer looks a lil something like this:
# config/initializers/zeitwerk_view_component_previews.rb
unless Rails.env.development? || Rails.env.test?
Rails.autoloaders.each do |autoloader|
autoloader.ignore(
Rails.application.config.view_component.preview_paths.flat_map { Pathname(_1).glob("**/*preview.rb") }
)
end
end
I think this is a pretty good idea to include something like this here so other folks can avoid this particular dumb trap.
melashu
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request