Skip to content

Commit 8f85b5c

Browse files
author
Gabe Scholz
committed
Create render_react_component controller helper
1 parent b0dd8c3 commit 8f85b5c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/react/rails.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
require 'react/rails/railtie'
22
require 'react/rails/engine'
3+
require 'react/rails/controller_helper'
34
require 'react/rails/view_helper'

lib/react/rails/controller_helper.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module React
2+
module Rails
3+
module ControllerHelper
4+
5+
# Render a React component as the view instead of
6+
# a template from the app/views folder.
7+
#
8+
def render_react_component(*args, &block)
9+
current_layout = _layout.virtual_path
10+
@__react_component_args = args
11+
@__react_component_block = block
12+
13+
render inline: '<%= react_component(*@__react_component_args, &@__react_component_block) %>', layout: current_layout
14+
end
15+
16+
end
17+
end
18+
end
19+
20+
ActionController::Base.send(:include, React::Rails::ControllerHelper) if defined?(Rails)

0 commit comments

Comments
 (0)