Skip to content

Commit

Permalink
Merge pull request #172 from bostanio/fix_autoload
Browse files Browse the repository at this point in the history
Fix Uninitialized Constant error #163
  • Loading branch information
joelhawksley authored Jan 6, 2020
2 parents bb107b4 + 60f539c commit 1429f36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/test/version_tmp/
/tmp/
/test/log/*
/test/app/tmp/*

# Used by dotenv library to load environment variables.
# .env
Expand Down
6 changes: 0 additions & 6 deletions lib/action_view/component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ def source_location
instance_method(:initialize).source_location[0]
end

def eager_load!
self.descendants.each do |descendant|
descendant.compile if descendant.has_initializer?
end
end

def compiled?
@compiled && ActionView::Base.cache_template_loading
end
Expand Down
10 changes: 9 additions & 1 deletion lib/action_view/component/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "rails"
require "action_view/component"

module ActionView
module Component
Expand All @@ -25,14 +26,21 @@ class Railtie < Rails::Railtie # :nodoc:
require "railties/lib/rails/components_controller"
require "railties/lib/rails/component_examples_controller"

app.config.eager_load_namespaces << ActionView::Component::Base
options = app.config.action_view_component

if options.show_previews && options.preview_path
ActiveSupport::Dependencies.autoload_paths << options.preview_path
end
end

initializer "action_view_component.eager_load_actions" do
ActiveSupport.on_load(:after_initialize) do
ActionView::Component::Base.descendants.each do |descendant|
descendant.compile if descendant.has_initializer? && config.eager_load
end
end
end

initializer "action_view_component.compile_config_methods" do
ActiveSupport.on_load(:action_view_component) do
config.compile_methods! if config.respond_to?(:compile_methods!)
Expand Down

0 comments on commit 1429f36

Please sign in to comment.