# How to have a Rails app inside a Rails app?

**URL:** <https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933>\
**Category:** Rails\
**Created:** [October 12, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933 "2006-10-12T13:50:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 12, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/1 "2006-10-12T13:50:28Z")

</div>

So I’m trying to figure out the best way to do this. I have my main  
rails app ready, but say I wanted to keep it separate from a front-end  
using the Mephisto rails app, whats the easiest way to do this? This  
way I can easily upgrade Mephisto when upgrades come out without having  
to merge all my code, controllers, modules in it etc.

The mephisto setup will be used for around 5-10 pages and I can then  
have the page/post management of Mephisto built right in. This will be  
at say [www.mydomain.com](http://www.mydomain.com). Then I want to have my app which is password  
protected and only for authenitcated users in something like  
[www.domain.com/myapp](http://www.domain.com/myapp) which has its own layouts, controllers modules,  
database etc.

In PHP this is as simple as nesting directories or separate apps, but  
in rails is quite different, especially taking into account deployment  
methods such as Capistrano and such.

Do I keep the apps separate and put a symlink to myapp’s public dir in  
the mephisto public dir? Will I have to do some fancy Rewrite rules?  
Would this even be possible on a virtual host or VPS or will I actually  
have to merge all my code in to Mephisto? If not I suppose I could use  
a PHP based front-end like wordpress and then have a link there to my  
rails app.

Right now I’d like to deploy on a Ubuntu VPS via Nginx and Mongrel  
Cluster but can also easily do Apache, mod\_proxy\_balancer, Mongrel.

Any advice would be greatly appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 12, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/2 "2006-10-12T14:41:43Z")

</div>

The easiest way is actually to use subdomains. Put your main app at  
[www.yoursite.com](http://www.yoursite.com). Put your other apps at [somethingelse.yourdomain.com](http://somethingelse.yourdomain.com).  
I  
wouldn’t get too hung up on nesting directories since you’re going to  
provide links for your users to click for navigation.

Another option is to just structure your application in such a way that  
your  
stuff is separate from their stuff. Rails is pretty well structured…  
you  
should be able to do it with relative ease.

You can also use some other more advanced methods like symlinks and  
rewrite  
rules. It’s going to depend largely on what your host will provide.

If the subdomains won’t work for you, let me know.

---

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 12, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/3 "2006-10-12T15:18:01Z")

</div>

Hey Brian,

Yeah, I was kinda thinking along the same lines, especially since the  
links will be taken care of by a consistent navigations in both  
templates subdomains would work.

I think I’ll give this a try first and if that doesn’t work perhaps  
look into symlinks and rewrite rules though that could get ugly :-\

---

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 13, 2006, 3:14am UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/4 "2006-10-13T03:14:57Z")

</div>

One thing about subdomains and just generally having a seperate Rails  
app file tree is how to do the database portion.

In my case I am thinking about integrating the Beast (beast.caboo.se)  
message forum into my site as a separate subdomain. If I share the same  
database I might prepend the table names with forum\_ or beast\_ so I  
don’t confuse myself. One thing to consider when using the same database  
like that is migrations. I’d most likely need to manually move the Beast  
migrations over to my main app’s db/migrate directory and in the proper  
order. Otherwise the migration version number will conflict between the  
two apps.

Another option is to use a separate database. Since I want to access  
some of the forum data in my main app, I’ll need to specify the  
different database for the forum data models there, but I think that is  
pretty straightforward.

I think I’ll wind up going with the separate database. That way the  
forum code is totally standalone, including db migrations.

---

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 18, 2006, 10:39am UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/5 "2006-10-18T10:39:16Z")

</div>

On 10/12/06, Marston [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hey Brian,
> 
> Yeah, I was kinda thinking along the same lines, especially since the  
> links will be taken care of by a consistent navigations in both  
> templates subdomains would work.
> 
> I think I’ll give this a try first and if that doesn’t work perhaps  
> look into symlinks and rewrite rules though that could get ugly :-\

If you’re using mongrel and http proxying, you could use mod\_rewrite  
to proxy the different directories to different packs of mongrels.

-ryan

---

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 18, 2006, 10:40am UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/6 "2006-10-18T10:40:51Z")

</div>

Carl,

Yes, I agree. I think I’ll do the same.

---

<div class="post-metadata">

**Author:** ![Marston](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Marston](https://www.ruby-forum.com/u/Marston)\
**Post date:** [October 18, 2006, 10:39am UTC](https://www.ruby-forum.com/t/how-to-have-a-rails-app-inside-a-rails-app/71933/7 "2006-10-18T10:39:25Z")

</div>

Well

if I have  
app1/  
and  
app2/controllerx  
and I want controllerx  
to ‘appear’  
on app1  
I create a controllerx on app1

in index() of controllerx,  
I have this:

request.request\_uri.to\_s

I feed that to something that connects to app2 for me.

example:

Net::HTTP.get\_response “host2”, request.request\_uri.to\_s

I then have access to a stream of HTML I need to deal with.

I usually dont do anything with it; I stuff it in a variable and  
then render that variable:

@disp\_this = (Net::HTTP.get\_response “host2”, request.request\_uri.to\_s  
).body

and…

\<%= @disp\_this %\>

demo:

[http://vietenglish.com/student/numbers](http://vietenglish.com/student/numbers)  
[http://vietenglish.com/td?db=ev&fmt=u&word=dictionary](http://vietenglish.com/td?db=ev&fmt=u&word=dictionary)

It appears that student and td are controllers in the same RAILS\_ROOT

But they are not.

td is actually served up by a Java based app server.

-Dan

On 10/12/06, Ryan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > look into symlinks and rewrite rules though that could get ugly :-\
> 
> If you’re using mongrel and http proxying, you could use mod\_rewrite  
> to proxy the different directories to different packs of mongrels.
> 
> -ryan
> 
> >

–  
removed\_email\_address@domain.invalid

> **[Bikle.com may be for sale - PerfectDomain.com](https://perfectdomain.com/domain/bikle.com)**
>
> Checkout the full domain details of Bikle.com. Click Buy Now to instantly start the transaction or Make an offer to the seller!
