Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some documentation about singleton resources in README.md

  • Loading branch information...
commit 832f8692bd47eb2b634fb93bad57e34855f693cb 1 parent bd89625
Olivier Lalonde authored October 04, 2012

Showing 1 changed file with 20 additions and 0 deletions. Show diff stats Hide diff stats

  1. 20  README.md
20  README.md
Source Rendered
@@ -58,6 +58,26 @@ In that case your handler should be:
58 58
 
59 59
 http://railwayjs.com/routing.html
60 60
 
  61
+### Singleton resources
  62
+
  63
+To create a singleton resource, set the singleton_for property of the
  64
+params hash to the resource you want the singleton resource to map to.
  65
+
  66
+Example usage:
  67
+
  68
+    map.resources('users');
  69
+    map.resources('account', { 
  70
+      singleton_for: 'users', 
  71
+      middleware: function(req, res, next) {
  72
+        // Set the id parameter since we don't get it from the URL
  73
+        // like is usually the case for normal resources.
  74
+        if(req.user)
  75
+          req.params.id = req.user.id;
  76
+        else 
  77
+          return res.redirect('/login');
  78
+        next(); 
  79
+    }});
  80
+
61 81
 ## Example app
62 82
 
63 83
 Check out [example app][1] to deal with middleware, route handling, and generic routes:

0 notes on commit 832f869

Please sign in to comment.
Something went wrong with that request. Please try again.