问题
I am using react_on_rails for developing a Rails Engine and an application.
I have written a rails engine which has a single component - NewComponent
. It uses react_on_rails. This has been tested via the dummy application of the rails engine. I imported and registered the component in dummy application:
/new_engine/test/dummy/client/app/Index.jsx
:
import NewComponent from '../../../../client/app/pages/user_home_page/NewComponent';
ReactOnRails.register({
NewComponent,
});
The above worked completely fine in the dummy app. And I was able to further render this registered component in the view.
Now I am consuming this react component as a mountable rails engine in a full fledged application. How can I import this component so that I can register it in the application? In the dummy application I was able to give a relative path to import the component. Such a relative path will not be possible in the application while consuming the gem.
I have checked online for an answer to this, but there seems to be very less documentation on react_on_rails with engines.
来源:https://stackoverflow.com/questions/46696659/importing-a-react-component-from-a-rails-engine-into-an-application