Looking at the code for route_resources
, it doesn't look like it will do anything beyond a bog-standard map.resources :foos
.
Instead, let's write our own method to deal with this issue, based on the original
def route_namespaced_resources(namespace, *resources)
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
sentinel = 'ActionController::Routing::Routes.draw do |map|'
logger.route "#{namespace}.resources #{resource_list}"
unless options[:pretend]
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
"#{match}\n map.namespace(:#{namespace}) do |#{namespace}|\n #{namespace}.resources #{resource_list}\n end\n"
end
end
end
We can start this off as a local method in your generator, which you can now call with:
m.route_namespaced_resources :admin, controller_file_name