Controller::Rewrite
layer can match and rewrite requests before they processed. This allows you to handle URLs like `/post/15/view` or `/blog/123-pictures-of-my-cat` easily. The basic rewrite operation is to extract some part of the path and optionally executes a block. That means that the path is modified before being passed on to the next layer in the controller, and controller instance variables may be set.
## Regular Expressions
In your `controller.rb`:
```ruby
prepend Rewrite, Actions
rewrite.extract_prefix permalink: /(?#{attributes[:post].content}
Integer("123")
to @post_id
.
### Matching.. other things
It's possible to match using Integer
, Float
, String
, and you can provide your own class which will be instantiated. If it doesn't match, raise an exception and the rewrite rule will fail.