All routing helpers, such as resources , scope , etc., are just functions inside your application routes. You can simply define a custom function as follows:
YourApplication.routes.draw do
I tested this in Rails 3.2, but it should work equally well in all 3.x versions.
I have included no null checks or begin/rescue blocks anywhere. Since you are going to use this custom function only when necessary, I assume that you will pass the correct and necessary parameters. If you said that you passed a fallback controller that does not exist, I would prefer that the route parsing fail, rather than trying to process it.
Edit: Typo in function arguments
Edit 2: Forget &block in function arguments
Edit 3: Add "_controller" to target_controller variable
source share