Requiring js with engine gem

I am having a go, for the first time, at making a gem which is an
engine. I have some javascript files which I have put in the
gem/app/assets/javascript. I can access those from the app but only
if I require them from the apps application.js. So if I have two js
files in the gem, say f1.js and f2.js, then in the apps application.js
I have to put
//= require f1
//= require f2

I have not been able to find a way to avoid having to require them all
individually. Is this possible?

Colin

Hi Colin,

I am having a go, for the first time, at making a gem which is an

engine. I have some javascript files which I have put in the

gem/app/assets/javascript. I can access those from the app but only

if I require them from the apps application.js. So if I have two js

files in the gem, say f1.js and f2.js, then in the apps application.js

I have to put

//= require f1

//= require f2

I have not been able to find a way to avoid having to require them all

individually. Is this possible?

What I usually do is something like this:

Let’s say that I have an engine called “my_engine”, then I would create a my_engine/app/assets/javascript/index.js which would have the content:

//= require f1

//= require f2

Then in the host app’s application.js you can call

// require my_engine

This is actually a very neat trick that Rails have to load files inside a folder. It will always look for an index.js file first.

I hope this helps,

// Marco

Hi Colin,

I am having a go, for the first time, at making a gem which is an

engine. I have some javascript files which I have put in the

gem/app/assets/javascript. I can access those from the app but only

if I require them from the apps application.js. So if I have two js

files in the gem, say f1.js and f2.js, then in the apps application.js

I have to put

//= require f1

//= require f2

I have not been able to find a way to avoid having to require them all

individually. Is this possible?

What I usually do is something like this:

Let’s say that I have an engine called “my_engine”, then I would create a my_engine/app/assets/javascript/index.js which would have the content:

//= require f1

//= require f2

Then in the host app’s application.js you can call

// require my_engine

Sorry, I meant: “//= require my_engine” here.

Hi Colin,

I am having a go, for the first time, at making a gem which is an
engine. I have some javascript files which I have put in the
gem/app/assets/javascript. I can access those from the app but only
if I require them from the apps application.js. So if I have two js
files in the gem, say f1.js and f2.js, then in the apps application.js
I have to put
//= require f1
//= require f2

I have not been able to find a way to avoid having to require them all
individually. Is this possible?

What I usually do is something like this:

Let's say that I have an engine called "my_engine", then I would create a
my_engine/app/assets/javascript/index.js which would have the content:

//= require f1
//= require f2

Then in the host app's application.js you can call

// require my_engine

This is actually a very neat trick that Rails have to load files inside a
folder. It will always look for an index.js file first.

Of course! It's obvious when you know how.

Thanks

Colin