From 0d6564a4cfcf1f9bd265edb55328826356c5dada Mon Sep 17 00:00:00 2001 From: Richard Macklin <1863540+rmacklin@users.noreply.github.com> Date: Fri, 7 Jul 2023 18:39:24 -0700 Subject: [PATCH] Only include url_helpers in Preview class when they are defined (#1795) Without this, we encounter the following error when running `bundle exec rake docs:build`: ``` Converting YARD documentation to Markdown files. rake aborted! NoMethodError: undefined method `routes' for nil:NilClass /Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/preview.rb:7:in `' /Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/preview.rb:6:in `' /Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/preview.rb:5:in `' /Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/base.rb:11:in `require' /Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/base.rb:11:in `' /Users/rmacklin/src/github.com/ViewComponent/view_component/Rakefile:81:in `require' /Users/rmacklin/src/github.com/ViewComponent/view_component/Rakefile:81:in `block (2 levels) in ' /Users/rmacklin/.asdf/installs/ruby/2.7.5/bin/bundle:23:in `load' /Users/rmacklin/.asdf/installs/ruby/2.7.5/bin/bundle:23:in `
' Tasks: TOP => docs:build (See full trace by running task with --trace) ``` --- docs/CHANGELOG.md | 4 ++++ lib/view_component/preview.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 72598c85b..80d7b5b04 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 5 ## main +* Avoid including Rails `url_helpers` into `Preview` class when they're not defined. + + *Richard Macklin* + * Allow instrumentation to be automatically included in Server-Timing headers generated by Rails. To enable this set the config `config.use_deprecated_instrumentation_name = false`. The old key `!render.view_component` is deprecated: update ActiveSupport::Notification subscriptions to `render.view_component`. *Travis Gaff* diff --git a/lib/view_component/preview.rb b/lib/view_component/preview.rb index e80087404..717acbd5b 100644 --- a/lib/view_component/preview.rb +++ b/lib/view_component/preview.rb @@ -4,7 +4,7 @@ module ViewComponent # :nodoc: class Preview - include Rails.application.routes.url_helpers + include Rails.application.routes.url_helpers if defined?(Rails.application.routes.url_helpers) include ActionView::Helpers::TagHelper include ActionView::Helpers::AssetTagHelper extend ActiveSupport::DescendantsTracker