Chris
Chris

Reputation: 469

How to share js/css/images across Rails applications?

I am currently trying to build 2 different Rails 3 applications, however, I want both applications to incorporate the same base styles and core javascript functions that I have created. What would be the best way to go about sharing those assets across the 2 apps so that I can still develop rapidly and not duplicate the assets and potentially get them out of sync?

Any suggestions are greatly appreciated.

Upvotes: 1

Views: 496

Answers (2)

davetron5000
davetron5000

Reputation: 24841

It's been a few years since this was asked and there are now some other solutions:

Both solutions involve providing meta-data for the package you want to share and then specifying that package in the app(s) that want to use them (in a Gemile for RubyGems or in Bowerfile/bower.json for Bower).

You then install the package, and add a reference to it in application.js and/or application.css, and you are off to the races!

Upvotes: 1

jaredonline
jaredonline

Reputation: 2902

I would setup a symlink system. Move the RAILS_ROOT/public/javascripts and RAILS_ROOT/public/images folders outside the RAILS_ROOT of both apps, and replace them with symlinks. So you'd have a directory structure like this:

root
   | 
    -app 1
       |
        - public
            |
             - images -> ../../../root/shared/public/images
            |
             - javascripts -> ../../../root/shared/public/javascripts
   | 
    -app 2
       |
        - public
            |
             - images -> ../../../root/shared/public/images
            |
             - javascripts -> ../../../root/shared/public/javascripts
   |
    - shared
        | 
         - public
             | 
              - images
             | 
              - javascripts

Upvotes: 0

Related Questions