1

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.

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

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

5 Comments

Thanks for the response. Correct me if I'm wrong, but I would probably need to set up the symlinks manually for each developer because the symlinks couldn't be added to a vcs? Maybe just a little script at the root that new debs could run once and not worry about it?
The other wrinkle is that development for this has to be done on Windows (XP to be exact). Would it be worth it to create a Rails plugin for this stuff?
Well... what exactly would the plugin do? Move everything into a parent directory and setup the symlink structure? It might be worth it. You might look into Capistrano, a deployment tool which does something similar. You may be able to bend it to what you want. And yes, you'll need to do this for every dev. I wasn't aware there was gonna be more than one. The only way around that would be to check the root directory into your repository, and have both apps in there (not ideal).
jaredonline, thanks for your help. I'm marking this as the answer because if I was using anything but windows I would do exactly what you stated above. We ended up creating a 3rd common app and just had both app1 and app2 hit app3 for the common assets.
Glad I could (sorta) help. I think your solution will work. A third option is setting up a server somewhere that just stores and serves the assets over the internet. Then you can configure ActionController::Base.asset_host in your config file to use that server assets.example.com. It seems like that's close to the mark on what you're doing anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.