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
ViewComponentHelpers.allow_rails_helpers
When using Rails helpers the :tag option only works when the server automatically reloads. But not on first launch.
:tag
Bridgetown Version: bridgetown 1.1.0 "Belmont"
bridgetown 1.1.0 "Belmont"
To Reproduce
tag
Current behavior If starting the app cold it crashes with the error produced below.
Note that if the tag helper is not used, then the server is started, then the tag helper is used it works as expected.
Expected behavior The tag helper should not raise an error.
Computing environment (please complete the following information):
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
Additional context
[Bridgetown] Starting: Bridgetown v1.1.0 (codename "Belmont") [Server] * Puma version: 5.6.5 (ruby 3.1.2-p20) ("Birdie's Version") [Server] * PID: 99909 [Frontend] touch frontend/styles/jit-refresh.css [Frontend] yarn run esbuild-dev [Frontend] yarn run v1.22.19 [Frontend] $ node esbuild.config.js --watch [Frontend] esbuild: frontend bundling started... [Frontend] esbuild: frontend bundling complete! [Frontend] esbuild: entrypoints processed: [Frontend] - index.EVFXU2NE.js: 78B [Frontend] - index.ETTOPBPI.css: 16.87KB [Bridgetown] Environment: development [Bridgetown] Source: /Users/joemasilotti/workspace/projects/masilotti.com/bridgetown/src [Bridgetown] Destination: /Users/joemasilotti/workspace/projects/masilotti.com/bridgetown/output [Bridgetown] Custom Plugins: /Users/joemasilotti/workspace/projects/masilotti.com/bridgetown/plugins [Bridgetown] Generating… [Bridgetown] Pagination: disabled. Enable in site config with pagination:\n enabled: true [Bridgetown] Conversion error: Bridgetown::Converters::ERBTemplates encountered an error while converting `index.erb' [Bridgetown] Stopping auxiliary processes... [Bridgetown] Exception raised: NameError [Bridgetown] undefined local variable or method `tag' for #<SiteComponent:0x00000001147bdff8 @view_context=#<Bridgetown::ERBView layout=default resource=index.erb>, @__vc_original_view_context=#<Bridgetown::ERBView layout=default resource=index.erb>, @output_buffer="", @lookup_context={"variants"=>[]}, @view_renderer=nil, @view_flow=nil, @virtual_path="/Users/joemasilotti/workspace/projects/masilotti.com/bridgetown/src/_components/site_component", @__vc_variant=nil, @current_template=nil, @__vc_content_evaluated=false, @__vc_render_in_block=nil, @helpers=#<Bridgetown::RubyTemplateView::Helpers:0x00000001147bd788 @view=#<SiteComponent:0x00000001147bdff8 ...>, @site=#<Bridgetown::Site "title"=>"Masilotti.com", "tagline"=>"Joe Masilotti’s blog on Ruby on Rails, iOS, Turbo Native, and automated testing.", "email"=>"joe@masilotti.com", "description"=>"A blog from Joe Masilotti, an independent developer who's passionate about clean, testable code.", "twitter"=>"joemasilotti", "github"=>"joemasilotti">, @context=#<struct Bridgetown::RubyTemplateView::Helpers::Context registers={:site=>#<Bridgetown::Site "title"=>"Masilotti.com", "tagline"=>"Joe Masilotti’s blog on Ruby on Rails, iOS, Turbo Native, and automated testing.", "email"=>"joe@masilotti.com", "description"=>"A blog from Joe Masilotti, an independent developer who's passionate about clean, testable code.", "twitter"=>"joemasilotti", "github"=>"joemasilotti">}>>> Did you mean? tap [Bridgetown] 1: /Users/joemasilotti/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-view-component-1.0.0/lib/bridgetown-view-component/bridgetown/view_component_helpers.rb:52:in `method_missing' [Bridgetown] 2: /Users/joemasilotti/workspace/projects/masilotti.com/bridgetown/src/_components/site_component.rb:7:in `call' [Bridgetown] 3: /Users/joemasilotti/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/view_component-2.74.1/lib/view_component/compiler.rb:112:in `render_template_for' [Bridgetown] 4: /Users/joemasilotti/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/view_component-2.74.1/lib/view_component/base.rb:131:in `render_in' [Bridgetown] 5: /Users/joemasilotti/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-core-1.1.0/lib/bridgetown-core/ruby_template_view.rb:31:in `render' [Bridgetown] Backtrace: Use the --trace option for complete information.
The text was updated successfully, but these errors were encountered:
Turns out you need to allow the Rails helpers before including the Bridgetown helpers.
This works:
class SiteComponent < ViewComponent::Base Bridgetown::ViewComponentHelpers.allow_rails_helpers :tag include Bridgetown::ViewComponentHelpers end
This does not work:
class SiteComponent < ViewComponent::Base include Bridgetown::ViewComponentHelpers Bridgetown::ViewComponentHelpers.allow_rails_helpers :tag end
Sorry, something went wrong.
@joemasilotti Ah, that makes sense. Maybe there's a way we can document this better or otherwise make it more obvious how it works?
Done! #687.
Successfully merging a pull request may close this issue.
When using Rails helpers the
:tagoption only works when the server automatically reloads. But not on first launch.Bridgetown Version:
bridgetown 1.1.0 "Belmont"To Reproduce
:taghelper from Railstaghelper in a componentCurrent behavior
If starting the app cold it crashes with the error produced below.
Note that if the
taghelper is not used, then the server is started, then thetaghelper is used it works as expected.Expected behavior
The
taghelper should not raise an error.Computing environment (please complete the following information):
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]Additional context
The text was updated successfully, but these errors were encountered: