Skip to content

Commit 8701c6c

Browse files
committed
Allow omitting the component name with props on render
1 parent f59f324 commit 8701c6c

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

lib/inertia_rails.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
require 'patches/mapper'
88

99
ActionController::Renderers.add :inertia do |component, options|
10+
if component.is_a?(Hash) && options[:props].nil?
11+
options[:props] = component
12+
component = true
13+
end
14+
1015
InertiaRails::Renderer.new(
1116
component,
1217
self,

spec/dummy/app/controllers/inertia_rails_mimic_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ def provided_props_test
2626
def default_component_test
2727
render inertia: true
2828
end
29+
30+
def default_component_with_params_test
31+
render inertia: { my: 'props' }
32+
end
2933
end

spec/dummy/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
get 'default_render_test' => 'inertia_rails_mimic#default_render_test'
4444
get 'transformed_default_render_test' => 'transformed_inertia_rails_mimic#render_test'
4545
get 'default_component_test' => 'inertia_rails_mimic#default_component_test'
46+
get 'default_component_with_params_test' => 'inertia_rails_mimic#default_component_with_params_test'
4647
get 'provided_props_test' => 'inertia_rails_mimic#provided_props_test'
4748

4849
post 'redirect_to_share_test' => 'inertia_test#redirect_to_share_test'

spec/inertia/rails_mimic_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424

2525
expect_inertia.to render_component('inertia_rails_mimic/default_component_test')
2626
end
27+
28+
it 'has the correct derived component with props' do
29+
get default_component_with_params_test_path
30+
31+
expect_inertia.to render_component('inertia_rails_mimic/default_component_with_params_test')
32+
.and have_exact_props({my: 'props'})
33+
end
2734
end
2835

2936
context 'no render is done at all and default_render is enabled' do

0 commit comments

Comments
 (0)