Reputation: 12121
Is it possible to have a single Ruby on Rails installations have multiple applications, that share a common model?
For example, I want to have a frontend application, as well as backend administration console, but both share the same model.
This is similar to the way Symfony works in PHP.
Thanks in advance!
Upvotes: 6
Views: 8157
Reputation: 815
The most common way to run multiple application in RoR is using the engine architecture. It has been used in quite a few production applications.
Here is the details in RoR documentation http://guides.rubyonrails.org/engines.html
Adding in this old question as i found this thread at first result as i searched google. Also the question is quite ambiguous as one might actually want a two totally decoupled application to run from the same RoR framework.(why? dont know...)
Upvotes: 0
Reputation: 1816
klew's suggestion worked out for me. I have a fully featured admin backend and needed a lean and focus API app.
I ended up using the rails_api gem for the second app and created it under a separate user account.
I'm using postgres as my database.
Then I had to do the following: edit database.yml to use the same database, username, password as the other app rather than copy files I used ln -s I linked schema.rb and any model.rb files that I wanted to use in the API. At this point I was able to use rails console in the API app.
As I'm using the rails_api gem I was obviously missing routes. This is probably a good thing as I was able to manually create specific routes as required and not expose anything else to the web.
I do not do any migrations in the API app, everything except the odd linking of a model.rb file is done in my original app.
Seems to be working nicely, thanks Klew!
Upvotes: 2
Reputation: 14977
The easiest way to have admin panel is to use namespaces. You just put all admin stuff to admin namespace. It is very common practice.
On the other hand, if you want to have two (or more) applications sharing the same database and models it is quite easy. I have one project that has two RoR applications sharing the same database. So here are my thoughts about it:
Hope it helps!
Upvotes: 16