How do I add custom options to ActionController::Routing::Routes map.resources?
-
10-07-2019 - |
Question
there are several places in my routes.rb file where I say:
map.resources :foo, :only => [:show, :index]
and I would like to be able to say:
map.resources :foo, :readonly => true
..or something of the like. I know this may seem kind of pointless, since it only saves a couple of characters, but I'd like to know how to do it so that I can add other more complicated options in the future.
Thx
-C
Solution
Not quite what you're looking for, but you could save some typing with Object#with_options:
map.with_options(:only => [:show, :index]) do |readonly|
readonly.resources :foo
readonly.resources :bar
...
end
Otherwise, you're probably looking at monkey patching or subclassing ActionController::Routing::RouteSet::Mapper
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow