phlex-rails icon indicating copy to clipboard operation
phlex-rails copied to clipboard

ArgumentError when rendering a partial from a `Phlex::Rails::Layout`

Open joeldrapper opened this issue 1 year ago • 2 comments

Hi!

I like this change. I needed something like this in the past.

However, it appears to have broken this kind of code:

class ApplicationLayout < Phlex::HTML
  include Phlex::Rails::Layout

  def view_template
    html do
      body do
        render partial: "tracking" # boom
      end
    end
  end
end

It raises:

     ArgumentError:
       wrong number of arguments (given 0, expected 1+)
     # /Users/kim/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/phlex-rails-1.2.1/lib/phlex/rails/layout.rb:48:in `render'

Originally posted by @Burgestrand in https://github.com/phlex-ruby/phlex-rails/issues/192#issuecomment-2060714585

joeldrapper avatar Apr 17 '24 08:04 joeldrapper

Worth mentioning is that in this particular case I could fix it by changing to render "tracking", and that this might in some way be related to https://github.com/phlex-ruby/phlex-rails/issues/137?

Burgestrand avatar Apr 17 '24 08:04 Burgestrand

This should have been covered by the if @_context check, which is essentially saying, “if we’re already rendering something, do the usual behaviour”. It’s because Rails interface for layouts is that they should respond to render, while everything else needs to respond to render_in. So frustrating. 😅

joeldrapper avatar Apr 17 '24 09:04 joeldrapper

This is fixed in main and v1. It will be in the next release.

joeldrapper avatar Sep 12 '24 09:09 joeldrapper

🎉

Burgestrand avatar Sep 14 '24 07:09 Burgestrand