Ad

How Do I Add Custom Options To ActionController::Routing::Routes Map.resources?

- 1 answer

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

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad