Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: no implicit conversion of nil into String #1738

Merged
merged 6 commits into from
May 26, 2023
Merged

TypeError: no implicit conversion of nil into String #1738

merged 6 commits into from
May 26, 2023

Conversation

donapieppo
Copy link
Contributor

When view-component is required in a Rails::Engine the variable
ViewComponent::Base.config.view_component_path is null and Regexp.quote(ViewComponent::Base.config.view_component_path)
raises TypeError: no implicit conversion of nil into String.

Checking defined?(Rails) && Rails.application seems to solve the problem.

May be related to #1565
but in 3.0.0 version.

`ViewComponent::Base.config.view_component_path` is null
and `Regexp.quote(ViewComponent::Base.config.view_component_path)`
raises `TypeError: no implicit conversion of nil into String`.

Checking `defined?(Rails) && Rails.application` seems to solve
the problem.
@joelhawksley
Copy link
Member

  1. Can you add a test that necessitates this change? Otherwise it could be easy for this fix to regress.
  2. Can you add a changelog entry?

@donapieppo
Copy link
Contributor Author

@joelhawksley I can try but I have no experience on how to test a gem against another gem :-).
I mean that the problem comes when you create an engine and use wiew_component in that engine.
So I gess I have to create a test engine and verify that the dummy rails app inside the engine does not raise the error.

Does it make sense?

@joelhawksley joelhawksley merged commit f7d26fa into ViewComponent:main May 26, 2023
@joelhawksley
Copy link
Member

@donapieppo sounds like it might not be worth the trouble. I'll merge as-is!

@donapieppo
Copy link
Contributor Author

Thanx!
I actually gave another look into the problems in my engine and in #1565. I add notes here just for reference.

Create the standard example blorgh engine as in rails documentation:

rails plugin new blorgh --mountable

and add spec.add_dependency "view_component" in blorgh.gemspec and require "view_component" in lib/blorgh.rb.

Than create a first component (for example app/components/blorgh/first_component.rb and app/components/blorgh/first_component.html.erb) and run the test. Everything is ok.

If in lib/blorgh.rb you add
require_relative "../app/components/blorgh/first_component"
or if you put the components in another path and require them you get the no implicit conversion of nil into String error. This is what is done in matey gem (#1565).

With this pull request it works also with the require of the component in lib/blorgh.rb.

claudiob pushed a commit to claudiob/view_component that referenced this pull request Dec 22, 2023
)

* When view-component is required in a Rails::Engine the variable
`ViewComponent::Base.config.view_component_path` is null
and `Regexp.quote(ViewComponent::Base.config.view_component_path)`
raises `TypeError: no implicit conversion of nil into String`.

Checking `defined?(Rails) && Rails.application` seems to solve
the problem.

* changelog

---------

Co-authored-by: Joel Hawksley <joel@hawksley.org>
claudiob pushed a commit to claudiob/view_component that referenced this pull request Jan 3, 2024
)

* When view-component is required in a Rails::Engine the variable
`ViewComponent::Base.config.view_component_path` is null
and `Regexp.quote(ViewComponent::Base.config.view_component_path)`
raises `TypeError: no implicit conversion of nil into String`.

Checking `defined?(Rails) && Rails.application` seems to solve
the problem.

* changelog

---------

Co-authored-by: Joel Hawksley <joel@hawksley.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants