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 :-\

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.

On 10/12/06, Marston [email protected] 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

Carl,

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

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/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. [email protected] 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


[email protected]