Zaq
Zaq

Reputation: 1274

Distributed Resource in Rails

I am planning a system that requires collaboration between many local Rails apps. The design calls for a global app to relay RESTful requests between these servers.

For example, imagine each school having a local Rails app, including a Teacher resource. I propose a global app which provides access to teachers as: /school/42/teacher/3

The School resource on the global server has a field for the base URL of the app at each school, so it can relay such a request to school_42_url/teacher/3.

The design calls for relaying, rather than having school servers connecting directly to each other.

I can think of several ways to achieve this but, being new to Rails, can't work out which one is 'the Rails way'.

  1. ActiveResource is appealing, but seems to require a fixed 'site' rather than setting it for each request.

  2. Routing, perhaps with URL globbing might work, but I need to see an example of how to achieve this.

  3. A third approach would be a custom Controller, but this doesn't feel like the Rails way.

To be clear, the combination of {school_id, teacher_id} is globally unique, but the global server need not store details of teachers, those are treated as a web resource.

Comments or suggestions welcome.

Upvotes: 1

Views: 60

Answers (2)

rudolph9
rudolph9

Reputation: 8119

It sounds like Pow may be what your looking for. It allows you to configure URL's for stack and rails application via symbolic links. It fits well in the rails model and may allow you to build your independent RESTful applications in the manor specified. I know their are methods for having independent rails servers work together but based this is a very low overhead approach and may be the way to go at-least for testing and development purposes.

Upvotes: 0

rajibchowdhury
rajibchowdhury

Reputation: 5544

You should use rails RESTful architecture on your client apps to expose apis (xml, json), and some library like Net::HTTP to call those apis from your server(main) app.

Upvotes: 2

Related Questions