Can we use regexp in routes map? I am creating a simple file browser. I have this route set in my /config/routes.js:
map.all('/assets/:folder.:format?', 'assets#index');
But the folder parameter could be (for example) Images/Logos, so I am interested if I can use regular expression for one.
In my ROR project I was able to solve the similar issue with the help of router' :contrains parameter:
match 'applications/:store/:platform/:identifier/:filename' => 'assets#direct_download',
:constraints => {
:store => /[\w.-]+/,
:platform => /[\w.-]+/,
:identifier => /[\w.-]+/,
:filename => /.+/
}
I was not able to find any examples. So I will be thankfull if somebody could clarify this for me.
You could use this syntax:
map.all(new RegExp('^\/assets\/(.*)$'), 'assets#index');
And then capture the parameters with its index (starting from 0 - the whole string is ignored, unlike the preg_match or similar functions):
// app/controllers/assets_controller.js
console.log(params[0]);