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