Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting undefined method `react_component' for... #38

Closed
odk211 opened this issue Jul 31, 2017 · 5 comments
Closed

Getting undefined method `react_component' for... #38

odk211 opened this issue Jul 31, 2017 · 5 comments

Comments

@odk211
Copy link

odk211 commented Jul 31, 2017

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

@renchap
Copy link
Owner

renchap commented Jul 31, 2017

Are you using Active Admin too?

@odk211
Copy link
Author

odk211 commented Aug 1, 2017

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

@philayres
Copy link

@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.

@odk211
Copy link
Author

odk211 commented Sep 6, 2017

@philayres When I use this gem, I use webpacker-react , webpacker in all environment.

@renchap
Copy link
Owner

renchap commented Sep 12, 2017

This should be fixed in the latest (0.3.2) release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants