phlex-ruby / phlex-rails

An object-oriented alternative to ActionView for Ruby on Rails.
https://www.phlex.fun
MIT License
232 stars 40 forks source link

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

Closed joeldrapper closed 2 months ago

joeldrapper commented 7 months ago

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

Burgestrand commented 7 months ago

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?

joeldrapper commented 7 months ago

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 commented 2 months ago

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

Burgestrand commented 2 months ago

🎉