Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using another gem's javascript in a Rails Engine

I'm trying to create a rails engine that will use javascript from a gem dependency that I have added to the engine. However I keep getting "couldn't find file 'fullcalendar'" when I put the following line in my application.js for my engine:

//= require fullcalendar

This line is loading the javascript from the gem dependency into the rails engine.

This same line will work when the gem is installed on a normal rails app (not engine). What am I missing here? Can an engine load javascript from another engine/gem?

UPDATE: Researching on my own the issue could be that sprockets only looks for javascript inside the engine. The gem dependency is installed into vendor/cache of the parent app NOT the engine therefore //require fullcalendar fails because it is looking within the engine and the javascript for fullcalendar is in the parent application.

What confuses me is that if I include fullcalendar in the parent application gemfile explicitly than I am able to access it in the engine. This doesn't make sense to me. In both instances the full calendar gems javascript is in the parent app, but the behavior is different. Including the gem in two places is unappelaing to me and doesn't seem like a proper solution. Any thoughts?

like image 845
John Avatar asked Nov 04 '22 13:11

John


1 Answers

I had some trouble with this in the past.

App > Engine 1 > Engine 2

Engine 1 and Engine 2 worked fine on the app. I created a dummy app in Engine 1 to test Engine 2's functionality, also worked fine. But when I put Engine 1 in App it didn't work at all.

My big mistake here was only including Engine 1 in App, Engine 2 has to be included as well! Inheritance does not work for Gemfiles, just dependencies.

like image 200
Vikko Avatar answered Nov 08 '22 05:11

Vikko