简体   繁体   中英

single installation of Rails for multiple apps

Can you have one installation of Rails and then use it for multiple apps. For example, I would like to have the following structure:

siteroot/app1 (rails)
siteroot/subsite1 (regular static html site)
siteroot/app2 (rails)
siteroot/subsite2 (regular static html site)

and so on...

What is the best practice for this?

It might be technically possible, but it's certainly not supported or intended. Convention over configuration, remember. When you make a new Rails application via rails appdir , you're making a single application, and everything in there is part of that one application. It is not an installation of Rails. Your Rails installation is off elsewhere (/var/lib/gems for me), and all that code that makes up Rails will be shared between multiple applications.

In short, the best practice is two separate apps in two seperate directories. There isn't really any reason for you to want to combine two applications. If they need to share resources or a database, it should be one app with different controllers, or two separate apps with common code distilled into a library or plugin.

Rails is just a framework built on top of the Ruby language.
It sounds like you're asking how to use one server, with Rails installed, to serve multiple Rails applications. So you need to start a web service for each app:

siteroot/app1 $ script/server -p 80 -e production (+ option for daemonize server, I forget)  
siteroot/app1 $ cd ../app2  
siteroot/app2 $ script/server -p 81 -e production (+ option for daemonize server, I forget)  

I'm a bit confused by your "subapps". Why are they subapps, why can't they be rendered by the same web service that handles the main app ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM