Getting undefined method `react_component' for...
odk211 opened this issue · 5 comments
How to reproduce
Install webpacker and webpacker-react.
https://github.com/rails/webpacker#installation
https://github.com/renchap/webpacker-react#installation
Gemfile
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
gem 'webpacker-react'
Install Commands
rails webpacker:install
rails webpacker:install:react
./bin/yarn add webpacker-react
Write some install stuff.
And when open page with <%= react_component 'SomeComponent' %>
I got this error.
ActionView::Template::Error (undefined method `react_component' for .....
Other info
Add Helper manually in ApplicationController and everything is fine.
class ApplicationController < ActionController::Base
helper Webpacker::Helper
end
I find related issue in webpacker.
rails/webpacker#172
That issue is closed with this PR
https://github.com/rails/webpacker/pull/288/files
I think the following hook is needed, but I'm not sure.
ActiveSupport.on_load :action_view do
include ::Webpacker::React::Helpers
end
react-rails has same code.
https://github.com/reactjs/react-rails/blob/master/lib/react/rails/railtie.rb#L60...L62
Are you using Active Admin too?
No, I do not use. But I use another rails engine blazer and health_check.
It seems health_check gem use ActionController::Base
https://github.com/ianheggie/health_check/blob/master/lib/health_check/health_check_controller.rb#L5
blazer use ApplicationController
https://github.com/ankane/blazer/blob/master/app/controllers/blazer/base_controller.rb#L2
@odk211 is gem webpacker
in your Gemfile in the production section, or just in a development and test block? I just struggled with this for hours, before realising that my issues were related to the gem not being available when I moved to production.
@philayres When I use this gem, I use webpacker-react
, webpacker
in all environment.
This should be fixed in the latest (0.3.2) release.