开发者

How do I set up rails apps as rack apps within another rails app?

(I believe this is doable, but just googling around, I haven't found开发者_如何学C any examples of it.)

Perhaps a more concrete example of what I'm asking. Suppose I have rails-3 apps already written: Foo, Bar, Baz, Qux. I have another application written: Master. Within Master I want to match routes and run the other apps in it. Since they are all rack-compatible, I imagine the routing in master would be something like this:

match "/foo" => Foo::Application
match "/bar" => Bar::Application
match "/baz" => Baz::Application
match "/qux" => Qux::Application

but I haven't figured out how to do it and where to actually put the code for the apps relative to the master app.


You probably want to catch things earlier than routing in the master application.

You can do this by going lower-level in to Rack; the Rack configuration file in the root of your Rails app called config.ru:

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)

run Rack::URLMap.new \
  "/"    => Master::Application,
  "/foo" => Foo::Application,
  "/bar" => Bar::Application

  # ... etc.

You can read more about Rack::URLMap here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜