How to have a Rails app inside a Rails app?

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. Then I want to have my app which is password
protected and only for authenitcated users in something like
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.

The easiest way is actually to use subdomains. Put your main app at www.yoursite.com. Put your other apps at 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.

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

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...

<!-- index.rhtml -->
<%= @disp_this %>

demo:

http://vietenglish.com/student/numbers
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

Carl,

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