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

turbo_stream helper block support - no method capture #3

Open
candland opened this issue May 14, 2023 · 2 comments
Open

turbo_stream helper block support - no method capture #3

candland opened this issue May 14, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@candland
Copy link

candland commented May 14, 2023

I'm testing out the Turbo support and found the turbo_stream helper errors when passing a block in an ERB template.

Am I doing something wrong?

  • It works if I create the turbo stream HTML without the helper.
  • It works if I use the helper without a block.

hello.rb

class Routes::Hello < Bridgetown::Rack::Routes
  route do |r|
    # route: POST /hello/:name
    r.post "hello", String do |name|
      if r.turbo_stream?
        r.respond_with_turbo_stream # Needed if not using the turbo_stream helper in the view
        render("hello", locals: {name: name})
      else
        r.redirect "/hello/#{name}"
      end
    end
  end
end

hello.erb

<% turbo_stream.append "turbo-test" do %>
  <p>Appended</p>
<% end %>
[Server]   Exception raised: NoMethodError
[Server] undefined method `capture' for #<RodaApp:0x0000000106a63d38 @_request=#<RodaApp::RodaRequest POST /hello/links>, @_response=#<RodaApp::RodaResponse 500 {} []>, @_request_timer=319009.257657, @_out_buf=nil, @turbo_stream=#<Turbo::Streams::TagBuilder:0x0000000106a3cc88 @view_context=#<RodaApp:0x0000000106a63d38 ...>, @render_method=:render>>

      @view_context.capture(&block)
                   ^^^^^^^^
[Server]                  1: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-turbo-1.0.0/lib/turbo/streams/tag_builder.rb:114:in `render_template'
[Server]                  2: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-turbo-1.0.0/lib/turbo/streams/tag_builder.rb:94:in `action'
[Server]                  3: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-turbo-1.0.0/lib/turbo/streams/tag_builder.rb:78:in `append'
[Server]                  4: /Users/dcandland/projects/proofreader/website-bridgetown/views/hello.erb:10:in `__tilt_5300'
[Server]                  5: /Users/dcandland/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/roda-3.67.0/lib/roda/plugins/render.rb:408:in `block in compiled_method_lambda'
@jaredcwhite
Copy link
Member

@candland Well, a couple of things. If you're using the render plugin for Roda, that's outside of Bridgetown's way of handling template rendering…Bridgetown's own ERB rendering solution supports capture.

Nonetheless, Roda has a plugin called capture_erb: http://roda.jeremyevans.net/rdoc/files/lib/roda/plugins/capture_erb_rb.html
and we should definitely support that as well. I'll try to get to that shortly.

@jaredcwhite jaredcwhite self-assigned this May 15, 2023
@jaredcwhite jaredcwhite added the bug Something isn't working label May 15, 2023
@candland
Copy link
Author

@jaredcwhite Yea, I'm using the render plugin. Is there a better / recommended way with the SSR stuff?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants