generate_routing_code(action)
private
This method creates nested route entry for namespaced resources. For eg.
rails g controller foo/bar/baz index Will generate - namespace :foo do
namespace :bar do
get 'baz/index'
end
end
# File railties/lib/rails/generators/rails/controller/controller_generator.rb, line 36
def generate_routing_code(action)
depth = 0
lines = []
# Create 'namespace' ladder
# namespace :foo do
# namespace :bar do
regular_class_path.each do |ns|
lines << indent("namespace :#{ns} do\n", depth * 2)
depth += 1
end
# Create route
# get 'baz/index'
lines << indent(%{get '#{file_name}/#{action}'\n}, depth * 2)
# Create `end` ladder
# end
# end
until depth.zero?
depth -= 1
lines << indent("end\n", depth * 2)
end
lines.join
end