You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 in ApplicationViewComponentPreview so I can call build instead of FactoryBot.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.
The text was updated successfully, but these errors were encountered:
palkan
changed the title
Zeitwerk should ignore Preview files in non-Dev/Test env(?)
Zeitwerk should ignore preview files when previews are disabled
Sep 28, 2022
Discussed in #24
Originally posted by dhnaranjo September 23, 2022
Hello! So I'm trying to do the following:
app/components/component_name
FactoryBot::Syntax::Methods
inApplicationViewComponentPreview
so I can callbuild
instead ofFactoryBot.build
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:
I think this is a pretty good idea to include something like this here so other folks can avoid this particular dumb trap.
The text was updated successfully, but these errors were encountered: