Skip to content

Commit c1eff92

Browse files
author
Kai Wood
committed
Add ability to render custom attributes from the controller
Currently, all custom attributes are sliced from options when using the controller renderer, instead of forwarding it to the view helper, making it impossible to set a custom class name or id. This patch changes the behaviour to act more like render_component.
1 parent 0573ae2 commit c1eff92

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

lib/react/rails/controller_renderer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(options={})
1212

1313
def call(name, options, &block)
1414
props = options.fetch(:props, {})
15-
options = options.slice(:data, :tag).merge(prerender: true)
15+
options = options.merge(prerender: true)
1616
react_component(name, props, options, &block)
1717
end
1818
end

test/dummy/app/controllers/server_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def console_example_suppressed
1616
end
1717

1818
def inline_component
19-
render component: 'TodoList', props: { todos: ['Render this inline'] }, tag: 'span'
19+
render component: 'TodoList', props: { todos: ['Render this inline'] }, tag: 'span', class: 'custom-class', id: 'custom-id'
2020
end
2121
end

test/server_rendered_html_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,8 @@ def wait_to_ensure_asset_pipeline_detects_changes
6161
assert_match(/<\/ul><\/span>/, rendered_html, "it accepts a tag override")
6262
# make sure that the layout is rendered with the component
6363
assert_match(/<title>Dummy<\/title>/, rendered_html)
64+
# make sure that custom html attributes are rendered
65+
assert_match(/class=\"custom-class\"/, rendered_html)
66+
assert_match(/id=\"custom-id\"/, rendered_html)
6467
end
6568
end

0 commit comments

Comments
 (0)