简体   繁体   中英

How to use jquery in non-react javascript on rails?

I've recently incorporated The react_on_rails (NOT react-rails ) Gem into my rails 4.2 code base.

I want to introduce new react components into an app that already has a fair amount of javascript code.

I ran the "hello world" generator for react on rails which, among other things, commented out the //= require jquery line from my application.js -- as a result of this my pre-existing coffeescript (which depended on jquery being present) no longer works. But the new generated demo hello world react components do work.

When i comment out the added //= require vendor-bundle and //= require app-bundle lines from my application.js and add back in the //= require jquery lines -- the opposite happens, the react components stop working but the pre-existing coffeescript works again.

My question is -- how do i set things up so that BOTH work? That is, that the new react components work, AND the pre-existing coffeescript (that relies on jquery) works as well.

Thanks in advance!

I haven't used the generator, so I'm not sure what all it contains. But I do have the react-rails gem and jquery working in a bunch of my apps, so here's what my imports look like;

application.js

//= require jquery
//= require react
//= require jquery_ujs
//= require react_ujs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM