react_on_rails: Undefined method react_component

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'

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 50 (27 by maintainers)

Most upvoted comments

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.

I had the same issue an existing app. I added an include ReactOnRailsHelper to application_helper and that worked.

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

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: image

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.

As far as I can tell:

  1. A gem that’s a Rails Engine (which React on Rails is) will automatically have helpers installed.
  2. We could document the addition of this snippet in ones initializer: ruby ActiveSupport.on_load(:action_view) do include ReactOnRailsHelper end
  3. Alternately, we could add that that here, to 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’m unfortunately getting the same error with matching stack trace. Tried clearing out my gems and re-installing everything but no avail.