instance method
add_resource_route
Ruby on Rails 3.2.22.5
Since v3.2.22.5 Last seen in v3.2.22.5Signature
add_resource_route()
Properly nests namespaces passed into a generator
$ rails generate resource admin/users/products
should give you
namespace :admin do
namespace :users
resources :products
end
end
Source
# File railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb, line 16
def add_resource_route
return if options[:actions].present?
# iterates over all namespaces and opens up blocks
regular_class_path.each_with_index do |namespace, index|
write("namespace :#{namespace} do", index + 1)
end
# inserts the primary resource
write("resources :#{file_name.pluralize}", route_length + 1)
# ends blocks
regular_class_path.each_index do |index|
write("end", route_length - index)
end
# route prepends two spaces onto the front of the string that is passed, this corrects that
route route_string[2..-1]
end
Defined in railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb line 16
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Rails::Generators::ResourceRouteGenerator