# How best to share code between apps?

**URL:** <https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409>\
**Category:** Rails\
**Created:** [February 16, 2009, 3:26am UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409 "2009-02-16T03:26:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 3:26am UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/1 "2009-02-16T03:26:26Z")

</div>

I come from a PHP environment where we have a “library” of sorts that  
contains various functionality in the form of object-oriented  
classes. The classes can be tied into any new project and the  
functionality of that class is gained without any duplication of  
coding efforts.

In learning Ruby on Rails, I’d like to create something similar for  
use in developing Rails applications. Is there a best practice for  
said “library” of functionality? How best is this code base shared  
between applications? Most importantly, how can updates to said  
library be easily reflected across all applications?

For instance, we want to have a single login/logout user capability  
between applications, since all of our applications will share the  
same userbase. I know restful\_authentication exists, but I’m working  
on rolling my own as a learning exercise.

Give a User Model, Session (login/logout) and User (registration/  
activation) Controllers, and an Authentication Module, what is the  
best way to share this code set across applications?

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 4:00am UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/2 "2009-02-16T04:00:25Z")

</div>

Plugins.

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 4:01am UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/3 "2009-02-16T04:01:02Z")

</div>

Plugins.

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 5:57am UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/4 "2009-02-16T05:57:22Z")

</div>

But aren’t plugins packaged with the application? How does that work  
for updates to the code?

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 10:10am UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/5 "2009-02-16T10:10:54Z")

</div>

On 16 Feb 2009, at 05:56, ericindc wrote:

> But aren’t plugins packaged with the application? How does that work  
> for updates to the code?

Plugins as git submodules.

Google search will probably reveal more, but this is one I came across  
just now:  
[http://woss.name/2008/04/09/using-git-submodules-to-track-vendorrails/](http://woss.name/2008/04/09/using-git-submodules-to-track-vendorrails/)

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/6 "2009-02-16T12:22:45Z")

</div>

I second plugins as git submodules. My company has built up a suite  
of standard plugins we use in apps for various things, and with git  
submodules it’s easy to cascade updates to those plugins to all the  
apps that use them.

I’ll give you a piece of advice that took me forever to sort out. The  
two following commands are not equivalent:

(Assuming vendor/plugins/my\_plugin is the root of your submodule)  
$ git add vendor/plugins/my\_plugin  
$ git add vendor/plugins/my\_plugin/

The trailing slash (often added my tab completion) gives you all sorts  
of problems with submodules. Beware! 😉

Cheers,  
Darrik

---

<div class="post-metadata">

**Author:** ![snowbird122](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Post date:** [February 16, 2009, 12:31pm UTC](https://www.ruby-forum.com/t/how-best-to-share-code-between-apps/160409/7 "2009-02-16T12:31:34Z")

</div>

> But aren’t plugins packaged with the application? How does that work  
> for updates to the code?

even in “the old days” (way back when everyone was still using  
subversion - must have been at least a year ago) this was possible.  
today (with git) it’s more or less the same.  
store your plugin’s code in a repository. inside your application  
checkout this plugin and everytime you commit any changes to the code  
in your repository, just update your plugin.
