Skip to content

Commit f146b2b

Browse files
committed
Added documentation on regex route components
1 parent 9103bcc commit f146b2b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

documentation/routes.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ App = Webmachine::Application.new do |app|
2020
# but will not provide any path_info
2121
add ["orders", :*], OrderResource
2222

23+
# Will map to any path that matches the given components and regular expression
24+
# Any capture groups specified in the regex will be made available in
25+
# request.path_info[:captures. In this case, you would get one or two
26+
# values in :captures depending on whether your request looked like:
27+
# /orders/1/cancel
28+
# or
29+
# /orders/1/cancel.json
30+
add ["orders", :id, /([^.]*)\.?(.*)?/], OrderResource
31+
32+
# You can even use named captures with regular expressions. This will
33+
# automatically put the captures into path_info. In the below example,
34+
# you would get :id from the symbol, along with :action and :format
35+
# from the regex. :format in this case would be optional.
36+
add ["orders", :id, /(?<action>)[^.]*)\.?(?<format>.*)?/], OrderResource
37+
2338
# will map to any path
2439
add [:*], DefaultResource
2540
end
@@ -94,4 +109,4 @@ end
94109
request.path_info[:foo]
95110
=> "bar"
96111

97-
```
112+
```

0 commit comments

Comments
 (0)