Skip to content

Commit

Permalink
Only include url_helpers in Preview class when they are defined (#1795)
Browse files Browse the repository at this point in the history
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 `<class:Preview>'
/Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/preview.rb:6:in `<module:ViewComponent>'
/Users/rmacklin/src/github.com/ViewComponent/view_component/lib/view_component/preview.rb:5:in `<top (required)>'
/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 `<top (required)>'
/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 <top (required)>'
/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 `<main>'
Tasks: TOP => docs:build
(See full trace by running task with --trace)
```
  • Loading branch information
rmacklin authored Jul 8, 2023
1 parent f73592f commit 0d6564a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d6564a

Please sign in to comment.