Just finished installing this as per the readme and I'm getting this:
NoMethodError - undefined method `react_component' for #<#<Class:0x007fc6e9ac2300>:0x007fc6e9ac1130>:
17:25:26 web.1 | app/views/hello_world/index.html.erb:2:in `_app_views_hello_world_index_html_erb__2737803353613407809_70246181992240'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/template.rb:145:in `block in render'
17:25:26 web.1 | activesupport (4.1.13) lib/active_support/notifications.rb:161:in `instrument'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/template.rb:339:in `instrument'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/template.rb:143:in `render'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
17:25:26 web.1 | activesupport (4.1.13) lib/active_support/notifications.rb:159:in `block in instrument'
17:25:26 web.1 | activesupport (4.1.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
17:25:26 web.1 | activesupport (4.1.13) lib/active_support/notifications.rb:159:in `instrument'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/template_renderer.rb:53:in `render_template'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/template_renderer.rb:17:in `render'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/renderer.rb:42:in `render_template'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/renderer/renderer.rb:23:in `render'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/rendering.rb:99:in `_render_template'
17:25:26 web.1 | actionpack (4.1.13) lib/action_controller/metal/streaming.rb:217:in `_render_template'
17:25:26 web.1 | actionview (4.1.13) lib/action_view/rendering.rb:82:in `render_to_body'
17:25:26 web.1 | actionpack (4.1.13) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
17:25:26 web.1 | actionpack (4.1.13) lib/action_controller/metal/renderers.rb:32:in `render_to_body'
17:25:26 web.1 | actionpack (4.1.13) lib/abstract_controller/rendering.rb:25:in `render'
17:25:26 web.1 | actionpack (4.1.13) lib/action_controller/metal/rendering.rb:16:in `render'
17:25:26 web.1 | actionpack (4.1.13) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
This is an odd error. Do you have React On Rails v5.2 installed?
@justin808 Yes
# Gemfile.lock
react_on_rails (5.2.0)
$ bundle show react_on_rails
/Users/mark/.rvm/gems/ruby-2.1.2/gems/react_on_rails-5.2.0
Isn't the helper supposed to be included something like this?:
See http://pothibo.com/2013/06/customize-rails-view-controller-with-railtie/
and https://github.com/reactjs/react-rails/blob/master/lib/react/rails/railtie.rb#L42-L44
@MarkMurphy What's odd is that you're the only seeing this issue. What version of rails are you using?
@justin808 4.1.13
@MarkMurphy Feel free to re-open this if you think this is a general issue.
@jbhatab Can you take a peek at this?
@samnang Any opinion?
@MarkMurphy very weird. was this from a fresh install?
yes it was
actually sorry, no it wasn't
@MarkMurphy do you have react-rails installed on your system too?
I did at one point, not sure if it was there at the same time. I went back to using react rails because of this issue.
@MarkMurphy very weird. My first thought is to clear out your local gems before installing react_on_rails.
I'm unfortunately getting the same error with matching stack trace. Tried clearing out my gems and re-installing everything but no avail.
Does the fix suggested by @MarkMurphy work:
See http://pothibo.com/2013/06/customize-rails-view-controller-with-railtie/
and https://github.com/reactjs/react-rails/blob/master/lib/react/rails/railtie.rb#L42-L44
@tmock12 Did you do this from fresh install?
Just tried a fresh rails install with react_on_rails 5.2.0 and it worked fine. Hmm....
Ideas @justin808?
@MarkMurphy @tmock12 could either of you put your sample in a repo that could help us to be able to re-produce the error?
@jbhatab I had react-rails installed before as well. I cleared all the gems but that didn't seem to help.
I haven't had a lot of time to look into it but I believe it has to do with the fact that I'm using an engine and was testing it inside the spec/dummy app.
adding this to an initializer fixed the problem for me:
ActiveSupport.on_load(:action_view) do
include ReactOnRailsHelper
end
@justin808 @samnang very weird. any ides on this one?
It's something to do with the engine setup.
Maybe this is just a doc issue with @tmock12 's comment above?
Or should we explicitly load?
The fact is that ReactOnRails is itself an engine.
I'd like to get this one closed. @jbhatab @tmock12 @MarkMurphy @samnang is this a doc change or a code fix? I really don't know.
@justin808 I'm not using this gem anymore but I believe it's a code fix. I think the code needs to be more explicit in loading the view helpers. See my previous comment
Again I'm using Rails v4.1.13 so try it out with that and see if you can reproduce the issue.
@tmock12 What version of Rails were you on when this happened to you?
@MarkMurphy Why did you switch off React on Rails?
I'm going to take a look at this issue.
I opted to build my react application from scratch (independently of my rails project) using something similar to the react boilerplate.
As far as I can tell:
ruby
ActiveSupport.on_load(:action_view) do
include ReactOnRailsHelper
end
engine.rb:module ReactOnRails
class Engine < ::Rails::Engine
config.to_prepare do
if File.exist?(VersionChecker::NodePackageVersion.package_json_path)
VersionChecker.build.warn_if_gem_and_node_package_versions_differ
end
ReactOnRails::ServerRenderingPool.reset_pool
end
end
end
Maybe @brandonhilkert might have an opinion. He wrote an article HOW TO BUILD A RAILS ENGINE
I posted this question here:
@MarkMurphy I ran a fresh install and got the error. You need to restart your server, run npm install in the client directory, and then run 'foreman start -f Procfile.dev'.
That fixed the issue for me.
@justin808 We may want to add better error messages for this though.
Thanks @jbhatab! @MarkMurphy Please let us know if this fixes your issue.
We may want to add better error messages for this though.
Not sure how we'd do that.
I've seen this problem on Rails 4.0. Restarting foreman didn't change it.
I think I'd just add the on_load code to the initializer if I was you. I did that locally, and it fixed it.
@jbhatab @justin808 I had already tried that before I posted this issue.
@MarkMurphy If you've got a PR that can include a test that shows why we'd need that, I'd be thrilled to review it!
@MarkMurphy @gma Have you tried the current version?
@justin808 I was using 6.1.0.
I'm afraid I'm back on react-rails now, having managed to work around the issue that brought me to react_on_rails in the first place.
I noticed plenty of people who'd had this problem reported that they'd had react_rails installed. I'd have mentioned it, only I suspect it was a red herring (at least in my case) as I created a branch for react_on_rails based on a commit that preceded my installation of react-rails.
I had same error with Rails 4.2.5.2 and this line in initializer helped me
ActiveSupport.on_load(:action_view) do include ReactOnRailsHelper end
Previously was installed react-rails:

@gma @beautyfree Is there any chance that you had both gems, react-on-rails and react-rails, installed at once?
@justin808 There's no question of that in my case, as I hard reset my repo to pre-date the installation of react-rails, which would have removed it from the bundle.
It would still have been on the system though.
I had the same issue an existing app. I added an include ReactOnRailsHelper to application_helper and that worked.
I just got this issue today on version 6.5.1 adding include ReactOnRailsHelper to application_helper worked fine.
@3den Please identify what is special about your app. I show in my videos how the generator on top of a new Rails 5 app works just fine.
it was working fine on 6.5.0 i just updated the gems and it stoped working
@3den can you back out the recent 6.5.1 update and see if that fixes your issue?
Did you update any other gems?
None of the changes for 6.5.1 look relevant to your issue.
I had this same issue installing 8.0.0 to my existing app on rails 4.2, I added the following snippet to the bottom of the react_on_rails.rb initializer, restarted the server and it worked. ActiveSupport.on_load(:action_view) do
include ReactOnRailsHelper
end
@damiong28 Any change to the docs or code needed? @gauravtiwari, have you seen this with Webpacker?
As all other developers here, I found this problem in my Rails 5 and React on Rails 8.0 setup. I thought it cause by my docker build setting but no.
I fixed it by adding ActiveSupport.on_load(:action_view) do include ReactOnRailsHelper end at the end of initializers/react_on_rails.rb or including ReactOnRailsHelper in application_helper.rb
I prefer to including ReactOnRailsHelper in application_helper.rb instead of messing up the generated react on rails config file.
@alexeyMohnatkin Can you take a look at this?
@samnang @mapreal19 I think we need to copy this pattern:
require "rails/railtie"
require "webpacker/helper"
class Webpacker::Engine < ::Rails::Engine
initializer :webpacker do |app|
ActiveSupport.on_load :action_controller do
ActionController::Base.helper Webpacker::Helper
end
ActiveSupport.on_load :action_view do
include Webpacker::Helper
end
Webpacker.bootstrap
Spring.after_fork { Webpacker.bootstrap } if defined?(Spring)
end
end
module Webpacker
extend self
def bootstrap
Webpacker::Env.load
Webpacker::Configuration.load
Webpacker::Manifest.load
end
def compile
Webpacker::Compiler.compile
Webpacker::Manifest.load
end
def env
Webpacker::Env.current.inquiry
end
end
require "webpacker/env"
require "webpacker/configuration"
require "webpacker/manifest"
require "webpacker/compiler"
require "webpacker/railtie" if defined?(Rails)
Closing as I believe this was fixed.
I had the same problem and adding the following in application_helper.rb worked
module ApplicationHelper
include ReactOnRailsHelper
end
I, too, still get this on Rails 6.0, and I too find the hack added to react_on_rails fixes it
Most helpful comment
As all other developers here, I found this problem in my Rails 5 and React on Rails 8.0 setup. I thought it cause by my docker build setting but no.
I fixed it by adding
ActiveSupport.on_load(:action_view) do include ReactOnRailsHelper endat the end ofinitializers/react_on_rails.rbor includingReactOnRailsHelperinapplication_helper.rbI prefer to including
ReactOnRailsHelperinapplication_helper.rbinstead of messing up the generated react on rails config file.