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!
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!
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With