3

I have a Rails website which has been divided into two separate projects - the public site, and the administration site.

As both sites are using the same database the models are shared between the applications (actually right now they are duplicated). The problem I have here is that when an update to the models occurs in the public project I need to copy the changes over into the admin project.

I've had a look around SO and noticed that there was a question which had answers suggesting using svn:external or git submodule, but I'm not entirely sure how to do this.

Essentially my aim is to be able to make the changes in one place only, commit those changes to git and then be able to pull the changes in the other project when I need to update that as well.

Community
  • 1
  • 1
Matthew Savage
  • 3,755
  • 9
  • 41
  • 52
  • Do the projects have their own databases or do they share one? – csexton Apr 27 '10 at 13:56
  • @csexton The projects share the one database - one project is the 'public' site, and the other project is the 'administration' site for the public site - hence the shared models. – Matthew Savage Apr 29 '10 at 08:50

2 Answers2

1

Do not use submodules. They are ugly, hard to understand and to maintain. Much better is to use subtrees.

Git subtree is a part of GIT since 1.7.11 and I wrote an article about sharing code between Rails applications: http://igor-alexandrov.github.com/blog/2013/03/28/using-git-subtree-to-share-code-between-rails-applications/

In short: yes git-subtree works and works great!

Igor Alexandrov
  • 236
  • 1
  • 5
1

You need to:

  • commit the submodule in one place
  • commit the main project (said the public site)
  • go to the same submodule in the other main project (the admin site)
  • pulling the latest content (changing the HEAD of that submodule)
  • going one directory up in the main (admin) project
  • commit (to record that you now reference a different version of the submodule)

See also true nature of submodules.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283