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

Fix ArgumentError: 'nil' is not an ActiveModel-compatible when rendering blocks #236

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/phlex/rails/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def render(*args, **kwargs, &block)
capture(*yielded_args, &block)
end,
)
else
return super
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/controllers/rendering_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

class RenderingController < ApplicationController
def standard_phlex
render Rendering::StandardPhlex.new
end

def partial_from_phlex
render Rendering::PartialFromPhlex.new
end
Expand Down
17 changes: 17 additions & 0 deletions test/dummy/app/views/rendering/standard_phlex.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Rendering
class StandardPhlex < ApplicationView
def view_template
render Header do
h1(id: "title") { "Hello Phlex!" }
end
end

class Header < ApplicationComponent
def view_template(&)
render(&)
end
end
end
end
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get "/helpers/missing_helper", to: "helpers#missing_helper"
get "/helpers/notice", to: "helpers#notice_test"

get "/rendering/standard_phlex", to: "rendering#standard_phlex"
get "/rendering/partial_from_phlex", to: "rendering#partial_from_phlex"
get "/rendering/view_component_from_phlex", to: "rendering#view_component_from_phlex"
get "/rendering/phlex_component_from_erb", to: "rendering#phlex_component_from_erb"
Expand Down
6 changes: 6 additions & 0 deletions test/phlex/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
require "test_helper"

class RenderTest < ActionDispatch::IntegrationTest
test "rendering standard phlex" do
get "/rendering/standard_phlex"
assert_response :success
assert_select "h1#title", "Hello Phlex!"
end

test "rendering partial from Phlex view" do
get "/rendering/partial_from_phlex"
assert_response :success
Expand Down